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.  执行结果

  • 相关阅读:
    USART串口通信实验
    EXTI 外部中断
    NVIC中断优先级管理
    实验1 跑马灯实验
    redis集群部署---一台主机
    zookeeper服务启动报错---Error contacting service. It is probably not running.
    shell脚本学习笔记
    最短路径算法——Floyd算法
    一篇文章学懂Shell脚本(摘抄)
    VIM空格和TAB转换
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/14932344.html
Copyright © 2011-2022 走看看