类,实例,属性习题


class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.restaurant_name=restaurant_name
self.cuisine_type=cuisine_type

def describle_restaurant(self):
print("打印的第一条消息")
print("打印的第二条消息")
def open_restaurant(self):
print("打印的最后一条消息")

new_res=Restaurant("小东",'餐厅')
print(new_res.cuisine_type)
print(new_res.restaurant_name)
new_res.describle_restaurant()
new_res.open_restaurant()

new_res1=Restaurant("娟娟","医院")
new_res1.describle_restaurant()

new_res2=Restaurant("lli","火锅馆")
new_res2.describle_restaurant()
'''
class User():
def __init__(self,first_name,last_name):
self.first_name=first_name
self.last_name=last_name

def describe_user(self):
print("My name is "+self.first_name+' '+self.last_name)

def describe_restaurant(self):
print("My first name is "+self.first_name)
print("My last name is "+self.last_name)

user1=User("gong","shelldon")
user1.describe_restaurant()
user1.describe_user()
posted @ 2019-03-08 12:10  Gshelldon  阅读(166)  评论(0编辑  收藏  举报