Reffering to member variables help


#1



Referring to member variables
https://www.codecademy.com/courses/python-intermediate-en-egNXj/0/6?curriculum_id=4f89dab3d788890003000096#

Traceback (most recent call last):
File "python", line 1, in
File "python", line 3, in Car
NameError: name 'Car' is not defined


I expect it to print the values listed for my_car


class Car(object):
    condition = "new"
    my_car = Car("supra", "blue", "20")

def __init__(self, model, color, mpg):
    self.model = model
    self.color = color
    self.mpg = mpg

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


#2

isn't Car defined on line 3?


#3

No, it's part of Car's definition
(And why would a Car be part of Car's definition?)


#4

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