题目描述
在Jupyter Notebook,定义类、创建实例,运行后提示创建实例的代码takes no arguments,实在找不到原因,麻烦帮小白看一下!
题目来源
《Python编程从入门到实践》习题
相关代码
class Restaurant():
def _init_(self, restaurant_name, cuisine_tpye):
self.restaurant_name = restaurant_name
self.cuisine_tpye = cuisine_tpye
my_restaurant = Restaurant("KFC","fast food")
提示错误
TypeError Traceback (most recent call last)
<ipython-input-3-c7d16ceda31f> in <module>
5 self.cuisine_tpye = cuisine_tpye
6
----> 7 my_restaurant = Restaurant("KFC","fast food")
TypeError: Restaurant() takes no arguments
定义类为啥要加括号?要么括号里面写(object)(python2需要),要么去掉括号:
或者: