目前通過Python的速成班工作,這個例子是給我找麻煩NameError:名「name」沒有定義
class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
""" initializing name and cuisine attributes"""
self.restaurant_name = name
self.cuisine_type = c_type
def greeting(self):
"""simulate greetting with restaurant info..."""
print(self.name.title() + " is a " + self.c_type.title()
+ " type of restaurant.")
def open_or_nah(self):
""" wheteher or not the restaurant is open in this case they will be always"""
print(self.name.title() + " is open af")
china_king = Restaurant('china king', 'chinese')
china_king.greeting
china_king.open_or_nah
控制檯一直給我
Traceback (most recent call last):
File "python", line 16, in <module>
File "python", line 4, in __init__
NameError: name 'name' is not defined
我搜索錯誤爲什麼造成這個原因,但我無法弄清楚。怎麼了?
你的參數被稱爲'restaurant_name' –