zoukankan      html  css  js  c++  java
  • TypeError: Restaurant() takes no arguments

    1. 错误描述

    TypeError: Restaurant() takes no arguments

     

    2. 原因:在编写__init__时,pycharm会自动添加关键字,有时会直接写称整型int, 即__int__。导致错误产生。

    ————————————————参考————————————————————————————————————————————————————————

    3. 错误代码

    # 9-1 restaurant
    class Restaurant():
        def __int__(self, restaurant_name, cuisine_type):
            self.restaurant_name = restaurant_name
            self.cuisine_type = cuisine_type
    
        def describe_restaurant(self):
            print("The " + self.restaurant_name + " have " +
                  str(self.cuisine_type) + " kinds of food.")
    
        def open_restaurant(self):
            print("Now is opening.")
    
    restaurant = Restaurant("'Restaurant of peace'", 108)
    restaurant.describe_restaurant()
    restaurant.open_restaurant()
    

      

    4. 正确代码

    class Restaurant():
        def __init__(self, restaurant_name, cuisine_type):
            self.restaurant_name = restaurant_name
            self.cuisine_type = cuisine_type
    
        def describe_restaurant(self):
            print("The " + self.restaurant_name + " have " +
                  str(self.cuisine_type) + " kinds of food.")
    
        def open_restaurant(self):
            print("Now is opening.")
    
    restaurant = Restaurant("'Restaurant of peace'", 108)
    restaurant.describe_restaurant()
    restaurant.open_restaurant()
    

      

      

    5.  执行结果

  • 相关阅读:
    linux扩展分区
    linux开机出现initramfs无法进入系统
    openCV编译安装-MSCV-Windows10-Qt
    Qt一键部署配置(Qt程序打包)
    Part8 升序排序 和降序排序
    Part7-.简单查询1
    Part6-向表中插入数据
    Part5-修改表(添加字段、删除字段、查看删除是否成功)
    Part4-删除表
    Part3-复制表
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/14932344.html
Copyright © 2011-2022 走看看