Python 创建实例例题9-1 《python 从入门到实践》
里面传参,函数定义明明是两个参数,但是我传两个会报错,我又传了一个,结果输出结果不对。

Python创建实例调用函数传参问题
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- 7*24 工作者 2023-02-09 17:00关注
class restaurant: def __init__(self,restaurant_name,cuisine_type): self.name = restaurant_name self.type = cuisine_type def describe_restaurant(self,restaurant_name,cuisine_type): #必须传递2个参数 print(f"The {restaurant_name} is {cuisine_type}") def open_restaurant(self,restaurant_name): #必须传递1个参数 print(f"The {restaurant_name} is opening>>>") c = restaurant('a3','big') c.describe_restaurant('a2','small') c.open_restaurant('a1')
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用