python 多继承的实现
第一类多继承的实现:from Child import Childdef main(): c = Child(300, 100) print(c.money, c.faceValue) c.play() c.eat() #注意:父类中方法名相同,默认调用的是在括号中排前面的父类中的方法 c.func()if __name__ == "__main__": main()第二类Mother:
class Mother(object): def __init__(self, faceValue): self.faceValue = faceValue def eat(self): print("eat") def func(self): print("func2")第三类Father:
class Father(object): def __init__(self, money): self.money = money def play(self): print("play") def func(self): print("func1")第四类Child
from Father import Fatherfrom Mother import Motherclass Child(Father, Mother): def __init__(self, money, faceValue): #写法 Father.__init__(self, money) Mother.__init__(self, faceValue)
相关推荐
tangjikede 2020-04-30
猛禽的编程艺术 2020-04-18
Laozizuiku 2020-04-10
meylovezn 2020-02-12
taiyangshenniao 2020-01-03
gaedmihx 2019-11-18
georgeandgeorge 2019-10-22
82467413 2012-06-18
程松 2019-04-08
HuangXiaoChuan 2018-01-09
wangcaipang 2012-03-04
无所畏惧 2019-06-17
ZGCdemo 2015-02-08
麋鹿麋鹿迷了路 2011-07-08
85437811 2014-03-28
linbossdeboke 2018-11-19
lookFuture 2018-11-15
albertjone 2018-09-15