6. Referring to member variables


#1

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        model = self.model
        color = self.color
        mpg = self.mpg
        
my_car = Car("DeLorean", "silver", 88)

print my_car.model
print my_car.color
print my_car.mpg

I don't see what I'm doing wrong here, it says that Car has no attribute model and that I haven't created the instance of my_car. Am I missing something?


#2

Hi,

Instead of model = self.model try self.model = model

The variable on the left is assigned the value of the expression on the right, and you are trying to set the member variable self.model to the value of the model parameter.


#3

ah, I get it now, thanks. Brain freeze.