class ElectricCar(Car): def __init__(self, model, color, mpg, battery_type): Car.__init__(self, model, color, mpg, "new") self.battery_type = battery_type my_car = ElectricCar("Rama", "red", 99, "molten salt")
you have two options here, either add model color and mpg to self again:
self.model = model # same for color and mpg
or you can use
super() to call the init method of the parent class
what you are doing is unfortunately not possible.
class ElectricCar(Car): def __init__(self, model, color, mpg,battery_type): self.battery_type = battery_type self.model = model self.color = color self.mpg = mpg
You still have an error? So yes, what?
I didn't understand how we can use super().
Could you explain please with an example.
Did you check other forum topics and documentation on how the
super() function works? It allows for calling parents methods
class C(B): def method(self, arg): super(C, self).method(arg)
It's can be some confusing that the first parameter in super is C, but remember - super gets the base class of C class.