#9-1 class Restaurant(): def __init__(self, restaurant_name, cuisine_type): self.restaurant_name=restaurant_name self.cuisine_type=cuisine_type def discribe(self): print(self.restaurant_name.title()+' is a '+self.cuisine_type.title()+' restaurant') def openrestaurant(self): print(self.restaurant_name+' is now openning') restaurant=Restaurant('Star','Chinese') restaurant.discribe() restaurant.openrestaurant() #9-2 a1=Restaurant('a1','west') a2=Restaurant('a2','india') a3=Restaurant('a3','Thai') a1.discribe() a1.openrestaurant() a2.discribe() a2.openrestaurant() a3.discribe() a3.openrestaurant() #9-3 class user(): def __init__(self,name, id , phone): self.name=name self.id=id self.phone=phone def discribe_user(self): print('user is '+self.name+' id is '+str(self.id)+' phone number is '+str(self.phone)) def greet_user(self): print('hello '+self.name) user1=user('jin',16337,10000) user2=user('king',12312,234234) user3=user('fun',123123,3232432324) user1.discribe_user() user2.discribe_user() user3.discribe_user() user2.greet_user() user1.discribe_user()
Star is a Chinese restaurant
Star is now openning
A1 is a West restaurant
a1 is now openning
A2 is a India restaurant
a2 is now openning
A3 is a Thai restaurant
a3 is now openning
user is jin id is 16337 phone number is 10000
user is king id is 12312 phone number is 234234
user is fun id is 123123 phone number is 3232432324
hello king
user is jin id is 16337 phone number is 10000
本文通过Python类实现的方式,介绍了如何创建餐厅类及用户类,并演示了如何使用这些类来实例化对象并调用其方法。示例中包含了不同类型的餐厅介绍及其营业状态,同时展示了用户信息描述及问候功能。
700

被折叠的 条评论
为什么被折叠?



