I don't understand how the code on line 17 works #9


#1

https://www.codecademy.com/courses/python-intermediate-en-egNXj/1/3?curriculum_id=4f89dab3d788890003000096#

No error messages

just want to know what it does,and how it works.

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, self.mpg)
    def drive_car(self):
        self.condition = "used"
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition
class ElectricCar(Car):
    def __init__(self, model, color, mpg, battery_type):
        Car.__init__(self, model, color, mpg)
        self.battery_type = battery_type
my_car = ElectricCar("toyota", "blue", 44, "molten salt")

#2

@xtimpossible,
You could use

my_car = ElectricCar("toyota", "blue", 44, "molten salt")
print my_car.condition
print my_car.display_car()
print my_car.battery_type
print("=my_car= constructed with {0}\n".format(type(my_car).__name__))
print("Who is the parent-Class of the constructor {0}".format(
      type(my_car).__name__))
print my_car.__class__.__bases__
print "==="
print my_car.drive_car.__class__
print dir(my_car)

http://stackoverflow.com/questions/625083/python-init-and-self-what-do-they-do?rq=1
http://stackoverflow.com/questions/34439/finding-what-methods-an-object-has