Overriding


#1



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


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

What is wrong with 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 %s %s with %s MPG." %(self.color, self.model,self.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

class ElectricCar(Car):
    def __init__(self,model, color,mpg,battery_type):
        self.model = model
        self.color = color
        self.mpg   = mpg
        self.battery_type=battery_type
        
    def drive_car(self):
        self.condition="like new"

my_car =ElectricCar("Jaguar", "Black", 95, "molten salt")
print my_car.condition()
my_car.drive_car()
print my_car.condition()


#2

here..

print my_car.condition()
Its not a method!!
get rid of

() i.e (parentheses)


#3

Oh No! Such a silly mistake. I got confused. Thanks @greentreemee.


#4

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