尝试在Python 3.7.0 IDLE中使用\u init时出错

2024-06-26 13:58:40 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我只是试着做同样的基础课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,如果这是一个新手的错误或什么的话,我很抱歉。你知道吗


Tags: 代码orgselfinit网站def错误shell