做题,遇到个无法理解的问题,为什么会无法调用
class Restauraut(object):
def __init__(self,restaurant_name,cuisine_type):
self.name=restaurant_name
self.type=cuisine_type
def describe_restaurant(self):
print(name,type)
def open_restaurant(self):
print("餐厅正在营业")
restaurant=Restauraut('KEC','Chinese food')
print('餐厅名称:'+restaurant.name())
Traceback (most recent call last):
File "D:\python\pycharm\pythonProject\class creation.py", line 12, in <module>
print('餐厅名称:'+restaurant.name())
TypeError: 'str' object is not callable
调用属性是: 列名.属性名
将括号去掉:print('餐厅名称:'+restaurant.name)
调用方法时才有():restaurant.open_restaurant()