【发布时间】:2018-03-07 01:50:49
【问题描述】:
我目前正在学习 python 的基础知识,我正处于紧张学习的第二天,我看不出我试图在哪里调用一个字符串:margaret_order.cuisine_style()。任何帮助将不胜感激。
class Restaurant():
'''Create simple restaurant details.'''
def __init__(self,name,cuisine):
'''Initialize name and cuisine type attributes.'''
self.name = name
self.cuisine = cuisine
def print_order(self):
"""Define individual who is ordering"""
print (self.name.title() + ' is the next individual to order.')
def cuisine_style(self):
'''Define the dish that the individual wants to order'''
print (self.cuisine() + ' Is the type of food that was ordered.')
jimmies_order = Restaurant('Jimmie','Fish Sandwhich')
margaret_order = Restaurant('Margaret','Lasagna')
margaret_order.cuisine_style()
我得到的错误是:
File "/Users/admin/Library/Preferences/PyCharmCE2017.3/scratches/scratch_3.py", line 15, in cuisine_style
print (self.cuisine() + ' Is the type of food that was ordered.')
TypeError: 'str' object is not callable
【问题讨论】:
-
错误告诉你究竟出了什么问题。您的
self.cuisine不是函数。只有在调用函数时才使用这些括号。只需删除它们。self.cuisine
标签: string python-3.x class oop