Class initialization failing

2019-09-14 18:58发布

# 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)

Error report:

Traceback (most recent call last):
  File "dog.py", line 13, in <module>
    d = Dog('Fido')
TypeError: object() takes no parameters

1条回答
Luminary・发光体
2楼-- · 2019-09-14 19:32

You have a typo. The method __int__ should be called __init__.

查看更多
登录 后发表回答