类初始化失败


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

相关内容

  • 没有找到相关文章

最新更新