尝试在Python 3.7.0 IDLE中使用_init_时出错 [英] Error when trying to use _init_ in Python 3.7.0 IDLE
本文介绍了尝试在Python 3.7.0 IDLE中使用_init_时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我只是想在Python.org的Python 3.7.0 IDLE(Shell)中执行相同的基本类工作,而当我尝试运行此代码时:
So I was just trying to do same basic Classes stuff in Python.org's Python 3.7.0 IDLE (Shell), and when I tried to run this code:
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
长颈鹿类中的init函数不是让Gerald接受参数 self 吗?
Doesn't the init function in class Giraffes make Gerald take parameter self?
我刚开始使用Python,因此很抱歉,如果这是新手错误或其他原因.
I'm just getting started with Python so sorry if this is a newbie mistake or something.
推荐答案
魔术方法)称为 __ init __
(每边两个下划线).
The constructor method (like other Python magic methods) is called __init__
(two underscores on each side).
这篇关于尝试在Python 3.7.0 IDLE中使用_init_时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文