个人对于python3继承的理解

#继承,这样理解就对了,你的就是我的,但是我的还是我的,但是你有我也有的,我就不稀罕你的,所以调用了父类的时候,self就是我,而不是你
class you:
    name='hxy'
    def __init__(self,name):
        self.name=name
    def youMoney(self):
        print('this is %s Money'%self.name)

    def House(self):
        print('this is %s House'%self.name)
        self.youMoney()

    def Car(self):
        print('this is %s car'%self.name)

class me(you):
    def __init__(self,name):
        self.name=name
    def Money(self):
        print('this is %s House'%self.name)

    def House(self):
        print('i used this is %s House'%self.name)

f1=me('my') #名字你有我也有,我用我的名
print(f1.name)
f1.House()#房子你有我也有,我用我的房
f1.youMoney()#钱嘛就要你的好了,我的先存起来
f1.Car()#我没车,就要你的车了


猜你喜欢

转载自blog.51cto.com/853056088/2133519