class Restaurant():
def __init__(self,name,type):
self.name = name
self.type = type
def restaurant_info(self):
print("饭店名字为:",self.name)
print("餐厅类型是:",self.type)
def open_restaurant(self):
print("本店正在营业!!!")
restaurant = Restaurant("青青草原","牧场")
restaurant.restaurant_info()
restaurant.open_restaurant()
print("-" * 30)
restaurant2 = Restaurant("赤色要塞","战场")
restaurant2.restaurant_info()
restaurant3 = Restaurant("寒冰射手","草丛")
print("-" * 30)
restaurant3.open_restaurant()
print("*"*46)
class User():
def __init__(self,name,age,sex):
self.name = name
self.age = age
self.sex = sex
def describe_user(self):
info = "名字:%s\t年龄:%s\t性别:%s"%(self.name,self.age,self.sex)
mh_info = info.expandtabs(15)#todo
print(mh_info)
def greet_user(self):
print("欢迎光临")
sun = User("孙悟空","500","男性")
zhu = User("猪八戒","800","男性")
sha = User("沙悟净","700","男性")
sun.describe_user()
zhu.describe_user()
sha.describe_user()
zhu.greet_user()
print(sha.name)
创建使用类
最新推荐文章于 2022-11-10 00:29:24 发布