你可以用
super(ChildClass, self).__init__()
class baseClass(object): def __init__(self, *args, **kwargs): passclass ChildClass(baseClass): def __init__(self, *args, **kwargs): super(ChildClass, self).__init__(*args, **kwargs)
您的缩进不正确,这是修改后的代码:
class Car(object): condition = "new" def __init__(self, model, color, mpg): self.model = model self.color = color self.mpg = mpgclass ElectricCar(Car): def __init__(self, battery_type, model, color, mpg): self.battery_type=battery_type super(ElectricCar, self).__init__(model, color, mpg)car = ElectricCar('battery', 'ford', 'golden', 10)print car.__dict__
这是输出:
{'color': 'golden', 'mpg': 10, 'model': 'ford', 'battery_type': 'battery'}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)