2024-10-03 02:38:11 发布
网友
下面是我写的代码 我试图在空闲状态下运行的是:
>>> mike = Frog('Mike', 'yell') >>> course = RaceCourse() >>> course.addFrog(julie) TypeError: addFrog() takes 1 positional argument but 2 were given
我对此特定部件的代码:
在Python中,当您使用类方法的对象调用它时,它会自动将self作为参数传递。在
在您的例子中,调用时提供了一个变量“julie”。在
所以你必须准备好函数来接受第二个参数 比如:
def addFrog(self, julie): # body
得到TypeError的原因是addFrog()函数只定义为接受1参数。在
TypeError
addFrog()
以下是修复的函数:
def addFrog(self, frog): self.turtle.pu() spacing = 350/(Frog.lastBib+1) Frog.height -= spacing self.turtle.goto(-250, Frog.height)
在Python中,当您使用类方法的对象调用它时,它会自动将self作为参数传递。在
在您的例子中,调用时提供了一个变量“julie”。在
所以你必须准备好函数来接受第二个参数 比如:
得到
TypeError
的原因是addFrog()
函数只定义为接受1参数。在以下是修复的函数:
相关问题 更多 >
编程相关推荐