如果我有一个 python 类:
class BaseClass(object):
#code and the init function of the base class
然后我定义了一个子类,例如:
class ChildClass(BaseClass):
#here I want to call the init function of the base class
如果基类的 init 函数接受一些我将它们作为子类的 init 函数的参数的参数,我如何将这些参数传递给基类?
我写的代码是:
class Car(object):
condition = "new"
def __init__(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
class ElectricCar(Car):
def __init__(self, battery_type, model, color, mpg):
self.battery_type=battery_type
super(ElectricCar, self).__init__(model, color, mpg)
我哪里错了?