个人对于python3继承的理解

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了个人对于python3继承的理解相关的知识,希望对你有一定的参考价值。

#继承,这样理解就对了,你的就是我的,但是我的还是我的,但是你有我也有的,我就不稀罕你的,所以调用了父类的时候,self就是我,而不是你
class you:
    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()#我没车,就要你的车了


以上是关于个人对于python3继承的理解的主要内容,如果未能解决你的问题,请参考以下文章