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 browser
1# Program to demonstrate multiple inheritance
2
3class Flyer:
4 def fly(self):
5 print("Can fly")
6
7class Swimmer:
8 def swim(self):
9 print("Can swim")
10
11class Duck(Flyer, Swimmer):
12 pass
13
14d = 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.