_init_
,但无法使其正常工作class Giraffes:
def _init_(self, spots):
self.giraffe_spots = spots
ozwald = Giraffes(100)
print(ozwald.giraffe_spots)
def __init__(self, spots):
您只在任一侧使用了一个。如果拼写错误,则在创建新实例时将不会调用它。
演示:>>> class Giraffes:
... def __init__(self, spots):
... self.giraffe_spots = spots
...
>>> ozwald = Giraffes(100)
>>> print(ozwald.giraffe_spots)
100