我正在设置一个类,并且第一步使用__init__函数来初始化属性。但是,当我尝试从该类创建实例时,它显示AttributeError。
我已经一遍又一遍地检查代码,看语法是否有问题,但错误仍然存在
class RandomWalk():
def ___init___(self, points = 10):
"""initialize attributes of a walk"""
self.points = points
self.x_values = [0]
self.y_values = [0]
rw = RandomWalk()
print(rw.points)
Run Code Online (Sandbox Code Playgroud)
我期望输出10作为默认值points,但错误显示:
Traceback (most recent call last):
File "test1.py", line 10, in <module>
print(rw.points)
AttributeError: 'RandomWalk' object has no attribute 'points'
Run Code Online (Sandbox Code Playgroud)
如果我用或替换属性points,问题仍然存在x_valuesy_values