Modifying member variables


#1

Hello! I need help with this section of the course:

this is my code

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    
    def display_car(self):
        return "This is a " + (self.color)+ " " +(self.model)+ " with "+ str(self.mpg) + " MPG."
    
    def drive_car(self):
        self.condition = "used"
            
my_car = Car("DeLorean", "silver", 88)

print my_car.condition()
my_car.drive_car()
print my_car.condition()

and the error i get is:
Traceback (most recent call last):
File "python", line 16, in
TypeError: 'str' object is not callable

what am I doing wrong?


#2

condition is a member variable, not a method. We have an instance (my_car) of class Car. To get a member variable do:

instance.memberVariable

no parentheses, that is for methods


#3

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