这里是关于类的相关问题
class IceCreamStand(R):def __init__(self,restaurant_name):
#super().__init__(restaurant_name,cuisine_type)
self.restaurant_name = restaurant_name
self.flavors = []
#添加风味
def add_flavors(self):
self.flavors = self.flavors.append(self.restaurant_name)
#展示所有的风味
def show_flavors(self):
print(f'本小店的冰淇淋有:')
for flavor in self.flavors:
print(f'\t{flavor}')
if __name__ == '__main__':
ice =IceCreamStand('kk_ice')
print(ice.flavors)
#添加一种风味
ice.add_flavors()
print(ice.flavors)
#展示所有风味
#ice.show_flavors()
导数第三行的print为啥会输入一个None值呢?不应该是个列表吗
self.flavors = self.flavors.append(self.restaurant_name)
改成
self.flavors.append(self.restaurant_name)
因为append方法返回None hrpzcf 发表于 2021-12-21 13:52
self.flavors = self.flavors.append(self.restaurant_name)
改成
self.flavors.append(self.restaurant_ ...
害,我犯了这种小错误!!!当局者迷旁观者清。谢谢哈
页:
[1]