Class initialization failing

醉酒当歌 提交于 2019-12-12 05:52:26

问题


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


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



来源:https://stackoverflow.com/questions/44611351/class-initialization-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!