zjmm19 发表于 2020-10-11 14:57:30

关于面向对象

class Restaurant():
    def _init_(self,restaurant_name,cuisine_type):
      self.restaurant_name=name
      self.cuisine_type=cuisine

    def describe_restaurant(self):
      print(self.name.title() + " provides " + self.cuisine.title())


    def open_restaurant(self):
      print(self.name.title()+'正在营业。')

restaurant=Restaurant ('四季','four seasons')
describe_restaurant(restaurant)
open_restaurant(restaurant)


这串代码为什么会报这个错误:Traceback (most recent call last):
File "C:/Users/zjm16/Desktop/python/25.py", line 13, in <module>
    restaurant=Restaurant ('四季','four seasons')
TypeError: Restaurant() takes no arguments
>>>

_2_ 发表于 2020-10-11 14:58:31

注意 __init__() 是双下划线
页: [1]
查看完整版本: 关于面向对象