我知道这个标题看起来很熟悉一些老问题,但我看过每一个,没有一个解决。 这是我的密码:
class Island (object):E,W,R,P
def __init__(self, x, y):
self.init_animals(y)
def init_animals(y):
pass
isle = Island(x,y)
但是,我得到了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in __init__
TypeError: init_animals() takes 1 positional arguments but 2 were given
如果我有什么错误,请告诉我,我很困惑。 致意
您需要添加
self
作为init_animals
的第一个参数:^{} (类似于Java中的
this
)是类的实例。每次调用类中的方法时,self
都会作为第一个参数发送到该方法。相关问题 更多 >
编程相关推荐