我的代码似乎有什么问题?我遇到了一个错误

时间:2019-07-17 17:35:40

标签: python-3.x class oop

class Dog():
    def __int__(self,breed,name,spots):

        self.breed = breed
        self.name = name
        self.spots = spots
my_dog = Dog(breed='lab',name='Sammy',spots='No Spots')

enter image description here

2 个答案:

答案 0 :(得分:1)

您有__int__,应该有__init__

答案 1 :(得分:-1)

In [7]: class Dog():
   ...:     def __init__(self, breed, name, spots):
   ...:         self.breed = breed
   ...:         self.name = name
   ...:         self.spots = spots
   ...:

In [8]: my_dog = Dog(breed='lab', name='Sammy', spots='No Spots')

__init__而不是__int__。只需更改值即可。