class IcecreamStand(Restaurant):
def __int__(self,restaurant_name,cuisine_type):
super.__init__(restaurant_name,cuisine_type)
self.flavors = ['choclate','banana','strawberry']
def present(self):
print(f"choose your icecream:{self.flavors}")
ice = IcecreamStand('shop','icecream')
ice.present()
Traceback (most recent call last):
File "D:\python_work\work\test.py", line 180, in <module>
ice.present()
File "D:\python_work\work\test.py", line 178, in present
print(f"choose your icecream:{self.flavors}")
AttributeError: 'IcecreamStand' object has no attribute 'flavors'
求指点
class IcecreamStand(Restaurant):
def __init__(self,restaurant_name,cuisine_type):
super.__init__(restaurant_name,cuisine_type)
self.flavors = ['choclate','banana','strawberry']
def present(self):
print(f"choose your icecream:{self.flavors}")
ice = IcecreamStand('shop','icecream')
ice.present()
你init拼错了,解释器就会以为这不是初始化,就没有定义flavers,当然报错了
def __init__ 这里是init