0
# 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
4

1 回答 1

4

你有一个错字。__int__应该调用该方法__init__

于 2017-06-18T03:07:40.110 回答