Member variables


#1

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print('This is a {color} {model} with {mpg} MPG.'.format(
            color=self.color,
            model=self.model,
            mpg=self.mpg))
    def drive_car(self):
        self.condition = "used"
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
print my_car.model
print my_car.color
print my_car.mpg
print my_car.condition
print my_car.drive_car()
print my_car.condition()

ERROR MESSAGE::Traceback (most recent call last):
File "python", line 21, in
TypeError: 'str' object is not callable

HELP!!!!1


#2

here:

print my_car.condition()

my_car.condition is a string, adding parentheses means python will attempt to call the string like a function call, which results in an error (string not callable)

you didn't have the parentheses before:

my_car = Car("DeLorean", "silver", 88)
print my_car.condition # no parentheses

not sure why you added them later


#3

oh!! I forget to remove these braces..btw thanks


#4