Initializing A Class


#1


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

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


#2

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

self.variable_name = variable_name
find any difference ?


#3

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.


#4

Try official documentations.
Docs


#5

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