所以我只是试着做同样的基础课Python.org网站的Python 3.7.0 IDLE(Shell),当我尝试运行以下代码时:
class Giraffes:
def _init_(self, spots):
self.giraffe_spots = spots
gerald = Giraffes(100)
它给了我这个错误:
Traceback (most recent call last):
File "<pyshell#69>", line 1, in <module>
gerald = Giraffes(100)
TypeError: Giraffes() takes no arguments
类Giraffes中的init函数不让Gerald接受参数self吗?你知道吗
我刚刚开始使用Python,如果这是一个新手的错误或什么的话,我很抱歉。你知道吗
constructor method(像其他Pythonmagic methods)被称为
__init__
(每边有两个下划线)。你知道吗相关问题 更多 >
编程相关推荐