multiple inheritance

A class inheriting from more than one parent class, searched left to right.

In more detail

A class such as class Duck(Swimmer, Flyer) inherits every method of both parents. When both define the same name, the parent listed first wins, because Python follows the method resolution order. Listing a class before one of its own subclasses makes the order impossible, and Python raises TypeError when the class is created.

Example

class Swimmer:
    def move(self): return 'swim'
class Flyer:
    def move(self): return 'fly'
class Duck(Swimmer, Flyer): pass
print(Duck().move())   # swim

Related terms

Taught in

References

Certification courses