TypeError: __init__() takes 3 positional arguments but 4 were given

class Restaurant():
    def __init__(self,restaurant_name,cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        self.number_served = 0
    def describe_restaurant(self):
        return(self.restaurant_name,self.cuisine_type,self.number_served)


class IceCreamStand(Restaurant):
    def __init__(self,restaurant_name,cuisine_type):
        super().__init__(self,restaurant_name,cuisine_type)
        self.flavors = ['苹果','芒果','草莓','榴莲']

    def IceCream_flavors(self):
        print("冰淇淋口味有以下几种:" + str(self.flavors))


get_flavors = IceCreamStand('幸福餐厅','中餐')
get_flavors.IceCream_flavors()

报以下错误:

get_flavors = IceCreamStand('幸福餐厅','中餐')

super().__init__(self,restaurant_name,cuisine_type)

TypeError: __init__() takes 3 positional arguments but 4 were given

问题是父类可接受的属性变量有3个,但是提供了4个;

解决方法:super().__init__(self,restaurant_name,cuisine_type)改为super().__init__(restaurant_name,cuisine_type);集成父类super的init参数不需要self;

 

你可能感兴趣的:(python学习,python)