1.多继承
class Shenxian: def fly(self): print('神仙会飞~') class Monkey: def eat_peach(self): print('猴子喜欢吃桃子') # 继承多个类 class MongkeyKing(Shenxian,Monkey): def play_stick(self): print('孙悟空玩金箍棒') m = MongkeyKing() # 子类对象可以执行多个父类中的方法 m.play_stick() m.fly() m.eat_peach()
2.多继承顺序(按顺序从左到右继承)
class Shenxian: def fly(self): print('神仙会飞~') def fight(self): print('神仙打架') class Monkey: def eat_peach(self): print('猴子喜欢吃桃子') def fight(self): print('猴子打架') # 当多继承父类中同时有两个重名方法时,先继承左边父类中发方法(继承顺序从左到右) class MongkeyKing(Shenxian,Monkey): def play_stick(self): print('孙悟空玩金箍棒') m = MongkeyKing() m.fight()
3.