#coding:gbk class Restaurant():#创建一个类, 首字母大写.从空白创建一个类,括号就是空的 '''习题9-1-3''' def __init__(self,restaurant_name,cuisine_type): # 初始化,第一个形参一定是self,后面是我所要的形参 '''初始化属性''' self.name = restaurant_name #自动将restaurant_name赋给name self.cuisine_type = cuisine_type#自动将cuisine_type赋值给cuisine_type def describe_restaurant(self):#类中的函数 都称为方法 '''描述''' print('\n'+self.name+'位于北极道上774号.') print('\n'+self.cuisine_type+'是餐厅的大小.') def open_restaurant(self):#类中的函数 都称为方法 '''开放餐厅''' print('\n'+self.name.title()+'正在营业') i = Restaurant('阿拉伯','17') print(i.name) print(i.cuisine_type) i.describe_restaurant() i.open_restaurant()
最后修改:2022 年 12 月 05 日
© 允许规范转载