Python-Classes :9.Inheritance


#1

Hello, Friends, I need your help with

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

Although my code passes correctly, I get a still strange output

new
used
<bound method ElectricCar.display_car of <ElectricCar object at 0x7fb9f2cb44d0>>
None


python


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,str(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
        
        
my_car=ElectricCar("Tesla","Red",100,"molten salt")
print my_car.display_car


What is the problem with my code?


#2

reason is..
here..

print my_car.display_car

display_car is a method and it needs parentheses!
print my_car.display_car()


#3

Before we answer, what is the problem with your code? This is YOUR question to be solved by YOU. Expect only insight from us.


#4

I solved the problem .It was parentheses at the end of the print statement.I wanted to know the meaning of error code.I looked up at stack-overflow, but couldn't found any definition etc.I want to know what is meant by "bound method " and what is this code "0x7fb9f2cb44d0"


#5

That is an address in RAM (the binding) where the slug is stored.


#6

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