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>>
# 应该是这样调用的吧
iss.describe_restaurant()
你调用的是 describe_restaurant 这个方法,调用方法时后面要带();
iss.describe_restaurant()
如果是属性才没有()