如何访问变量的值?
class Example:
def __init__(self):
self.food = "Soup"
def get_food(self):
return self.food
food_dict = {
"Soup": 3,
}
x = Example.get_food
for x in food_dict.keys():
print food_dict[x]
上面的操作员打印命令会导致语法错误。我试图返回该值,但这会导致 KeyError:0 消息。如何打印值?