python类的使用,代码语法无任何问题,百度一下发现是缩进问题!!!
class Restaurant:
def __init__(self,restaurant_name,cuisine_type):
self.name=restaurant_name
self.type=cuisine_type
def describe_restaurant(self):
print(self.name)
print(self.type)
def open_restaurant(self):
print("餐馆正在营业")
rest=Restaurant("好吃又美味","中国菜")
rest.describe_restaurant()
rest.open_restaurant()
结果1:
修改后:
class Restaurant:
def __init__(self,restaurant_name,cuisine_type):
self.name=restaurant_name
self.type=cuisine_type
def describe_restaurant(self):
print(self.name)
print(self.type)
def open_restaurant(self):
print("餐馆正在营业")
rest=Restaurant("好吃又美味","中国菜")
rest.describe_restaurant()
rest.open_restaurant()