Middle
Is there an option for multiple inheritance in Python?
sobes.tech AI
Answer from AI
Yes, Python supports multiple inheritance. This means that a class can inherit behavior and properties from more than one base class.
Example of multiple inheritance:
class A:
def method_a(self):
print("Method from class A")
class B:
def method_b(self):
print("Method from class B")
class C(A, B):
pass
obj = C()
obj.method_a() # Outputs: Method from class A
obj.method_b() # Outputs: Method from class B
In multiple inheritance, it is important to understand the method resolution order (MRO), which determines which method will be called if it is defined in multiple base classes.