首页 新闻 搜索 专区 学院

子类继承父类中出现问题

0
悬赏园豆:50 [待解决问题]

练习9-6~9-9

class Restaurant:
"""一次模拟餐厅的简单尝试"""

def __init__(self,restaurant_name,cuisine_type):
    self.restaurant_name = restaurant_name
    self.cuisine_type = cuisine_type
    self.number_served = 0
    
def set_number_served(self,number):
    self.number_served = number
    
def increment_number_served(self,number_1):
    self.number_served += number_1
    
def describe_restaurant(self):
    print(f"The restaurant name is {self.restaurant_name}.")
    print(f"The cuisine type is {self.cuisine_type}.")
    
def reset_number_served(self):
    self.number_served = 0
    
def open_restaurant(self):
    print("This restaurant is opening.")

class IceCreamStand(Restaurant):
def init(self,restaurant_name,cuisine_type):
"""
初始化父类的属性
再初始化冰淇淋店特有的属性
"""
super().init(restaurant_name,cuisine_type)
self.flavors= [1,2,3]

def describe_flavors(self):
    print(f"{self.flavors}")

iss = IceCreamStand("iss","sweet")
iss.describe_restaurant

<bound method Restaurant.describe_restaurant of <main.IceCreamStand object at 0x0000028316B763C8>>

不是子木呀的主页 不是子木呀 | 初学一级 | 园豆:152
提问于:2022-03-28 19:19
< >
分享
所有回答(2)
0
# 应该是这样调用的吧
iss.describe_restaurant()
Jruing | 园豆:267 (菜鸟二级) | 2022-04-02 10:31
0

你调用的是 describe_restaurant 这个方法,调用方法时后面要带();
iss.describe_restaurant()
如果是属性才没有()

小白沙 | 园豆:105 (初学一级) | 2022-04-10 13:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册