Multiple Inheritance

In Python a class can inherit from more than one class. The resulting class will have all the methods and attributes from the parent classes.

In essence, it’s called multiple inheritance because a class can inherit from multiple classes.

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Example

In the example below class C inherits from both class A and class B. If an object is created with class C, it has the methods of class A,B and C.

Keep in mind that if you create an object from class A or class B, they will only have the methods and attributes of those classes.

Visually this is what happens:

multiple inheritance

Previous Post
Next Post

Leave a Reply