Initializing A Class


This code passes, but I get an error message. Is this supposed to happen? I checked the next lesson and it continued without covering my error message, so I thought this had to be adressed here.

My interpretor gave this message:

Traceback (most recent call last):
File "python", line 7, in
File "python", line 4, in init
AttributeError: 'Car' object has no attribute 'model'

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.condition


While defining constructor variables...
we do this..

self.variable_name = variable_name
find any difference ?


Thanks, I was too lazy to review the syntax again. I'll try to refrain from using the forums until I've verified the syntax next time.


Try official documentations.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.