9. Inheritance


class Car(object):
    condition = "new"  # member variables: Saved in this class only

    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg = mpg

    def display_car(self):
        tmp = "This is a " + str(color) + " " + str(model) + " with " +                   str(mpg) + " MPG."
        return tmp
    def drive_car(self):
        self.condition = "used"

class ElectricCar (Car):
    def __init__(self,model, color, mpg,battery_type):
        self.battery_type = battery_type

model = "DeLorean"
color = "silver"
mpg = 88
my_car = ElectricCar(model, color, mpg, "molten salt")

Oops, try again. my_car does not appear to be an instance of ElectricCar

I don't know why is it. Please help me..

Replace this line with your code.




this is python2, you can't call super yet without any arguments. This was introduced in python3


Thank for your support. I have found the way to fix it.
We should use: super(ElectricCar, self).init(model, color, mpg).