Junior — Middle
What types of inheritance exist in the Python programming language?
sobes.tech AI
Answer from AI
In Python, the following types of inheritance exist:
- Single inheritance — a class inherits from one parent class.
class Parent:
pass
class Child(Parent):
pass
- Multiple inheritance — a class inherits from multiple classes.
class A:
pass
class B:
pass
class C(A, B):
pass
- Multilevel inheritance — a chain of inheritance where a class inherits from a class that itself inherits from another.
class Grandparent:
pass
class Parent(Grandparent):
pass
class Child(Parent):
pass
- Hierarchical inheritance — multiple classes inherit from a single parent.
class Parent:
pass
class Child1(Parent):
pass
class Child2(Parent):
pass
Python supports dynamic method resolution order (MRO), which is especially important in multiple inheritance to determine the method search order.