# Class and Instance Variables
class Dog:
kind = 'canine'
def __int__(self, name):
self.name = name
self.tricks = []
d = Dog('Fido')
e = Dog('Buddy')
print(d.kind)
print(e.kind)
print(d.name)
print(e.name)
错误报告:
Traceback (most recent call last):
File "dog.py", line 13, in <module>
d = Dog('Fido')
TypeError: object() takes no parameters
你有一个错别字。该方法__int__
应称为__init__
。