6 / Referring to member variables


#1
class Car(object):
     condition = "new"
my_car = car()  
print my_car.condition
def __init__(self, model, color, mpg):
    self.model = model
    self.color = color
    self.mpg = mpg
    my_car = car('DeLorean', 'silver', 88) 
print my_car.model 
print my_car.color 
print my_car.mpg
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
print my_car.model
print my_car.color
print my_car.mpg
`indent preformatted text by 4 spaces`

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

pls help ???


#2

Your class is Car but you wrote car(with a small c)

You are making a mistake

the class and its constructors should be implemented separately and then outside of it you begin to create objects of it


#3

Hum ! Could you further explain , where in the code do i need to add or change things ?.. thnx for your help :smile:


#4

this should be moved out of the class