7/11


#1



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


Why do I have to use self.color etc again in display_car if they are already set in init? This is the one thing that I just don't understand.


class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print ("This is a %s %s with %s MPG." % (self.color, self.model, self.mpg))

my_car = Car("DeLorean", "silver", 88)
print my_car.display_car()


#2

because you pass self as method parameter:

def display_car(self):

so you have access to all the properties that belong to self.