My code somehow works but I have a few doubts regarding it.
1) I have defined my_car as an object for Car as well as ElectricCar class(Followed instructions). So my_car is exactly which class's instance now?
2) We use inheritance so that we don't have to redefine variables and methods but here I have to reinitialise variables like model,color...etc. Now what's the point of inheriting then?
3) what is more efficient? redefining those variables(model,color,mpg) in the init class of electriccar using self or super is more efficient?
Thanks in advance. I am very new to inheritance so very confused
class Car(object): condition = "new" def __init__(self, model, color, mpg): self.model = model self.color = color self.mpg = mpg def display_car(self): return "This is a %s %s with %s MPG." % (self.color,self.model,str(self.mpg)) def drive_car(self): self.condition = "used" class ElectricCar(Car): def __init__(self,model, color, mpg, battery_type): super(ElectricCar,self).__init__(model,color,mpg) self.battery_type = battery_type my_car = Car("DeLorean", "silver",88) my_car = ElectricCar("test","blue",100,"molten salt") print my_car.condition my_car.drive_car() print my_car.condition