restaurant实例属性python_AttributeError:“Restaurant”对象没有“describe\u Restaurant”属性...

做一个叫餐厅的课程。Restaurant的init()方法应该存储两个属性:餐厅名称和菜肴类型。创建一个名为descripe_restaurant()的方法打印这两条信息,创建一个名为open_restaurant()的方法,该方法打印一条指示餐厅已营业的消息。

在你的课上创建一个名为restaurant的实例。分别打印两个属性,然后调用两个方法。在class Restaurant():

"""An attempt to model a restaurant"""

def __init__(self,restaurant_name,cuisine_type):

"""Initializing name and age attributes"""

self.name = restaurant_name

self.cuisine = cuisine_type

def describe_restaurant(self):

# Describes the restaurant name and cuisine

print(self.name.title() + " serves " + self.cuisine + " food.")

def open_restaurant(self):

# Opens the restaurant and welcomes customers.

print(self.name.title() + " is now Open. \nCome. \nHave some delicious " + self.cuisine + " food.")

restaurant1 = Restaurant("big chill","italian")

print(restaurant1.name)

print(restaurant1.cuisine)

restaurant1.describe_restaurant()

我得到的输出是:

^{pr2}$

为什么Python要把类的方法解释为属性?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值