【问题标题】:What seems to be wrong with my code? I'm running into a error [closed]我的代码似乎有什么问题?我遇到了一个错误[关闭]
【发布时间】:2019-07-17 17:35:40
【问题描述】:
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')

【问题讨论】:

  • __init__ 不是__int__
  • 请不要将图片作为文本发布,请将文本作为文本复制粘贴。

标签: python-3.x class oop


【解决方案1】:

你有__int__,你应该有__init__

【讨论】:

    【解决方案2】:
    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__。只需更改值即可。

    【讨论】:

    • 为什么我对这个答案投了反对票?有什么意义吗?
    猜你喜欢
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    相关资源
    最近更新 更多