python3 __init__ qusetion:TypeError:object .__ init __()不带参数

时间:2017-06-12 02:19:37

标签: python-3.x

python新手 使用python3.X
不知道如何解决

class Car():
        def __int__(self,make,model,year):
            self.make=make
            self.model=model
            self.year=year
    class ElectricCar(Car):
        def __init__(self,make,model,year):
            super().__init__(make,model,year)
    my_tesla =ElectricCar('tesla','model s',2016)

#TypeError: object.__init__() takes no parameters

1 个答案:

答案 0 :(得分:0)

你在Car.init()中拼错了init。它是__init__()而非init()试试这个:

class Car():
    def __init__(self,make,model,year):
        self.make=make
        self.model=model
        self.year=year
class ElectricCar(Car):
    def __init__(self,make,model,year):
        super().__init__(make,model,year)
my_tesla =ElectricCar('tesla','model s',2016)