Multiple Inheritance in Python
Duck(Flyer, Swimmer) gets methods from both. MRO decides who wins if names clash.
IntermediateObject-Oriented ProgramsExample 5 of 25
multiple-inheritance.py
Run in browser1# Program to demonstrate multiple inheritance23class Flyer:4 def fly(self):5 print("Can fly")67class Swimmer:8 def swim(self):9 print("Can swim")1011class Duck(Flyer, Swimmer):12 pass1314d = Duck()15d.fly()16d.swim()
Output
Can fly Can swim
What's going on
Duck inherits behaviors from both Flyer and Swimmer via multiple inheritance.