July 4, 2025

About

Python allows multiple inheritance, which can be useful but also confusing. To help you get started quickly, here’s a quick rundown of how to explicitly call parent class functions.

Multiple inheritance + ABC example with explicit init() calls

from abc import ABC, abstractmethod

class Base(ABC):
    @abstractmethod
    def do_something(self):
        pass

class A(Base):
    def __init__(self):
        print("A.__init__")
    
    def do_something(self):
        print("A.do_something")

class B(Base):
    def __init__(self):
        print("B.__init__")
    
    def do_something(self):
        print("B.do_something")

class C(A, B):
    def __init__(self):
        print("C.__init__")
        A.__init__(self)
        B.__init__(self)

    def do_something(self):
        print("C.do_something")
        A.do_something(self)
        B.do_something(self)

Call __init__ in super class with super

class Base:
    def __init__(self, name):
        print(f"Base.__init__: name = {name}")
        self.name = name

class A(Base):
    def __init__(self, name, age):
        print(f"A.__init__: age = {age}")
        super().__init__(name)
        self.age = age

class B(Base):
    def __init__(self, name, job):
        print(f"B.__init__: job = {job}")
        super().__init__(name)
        self.job = job

class C(A, B):
    def __init__(self, name, age, job):
        print("C.__init__")
        super().__init__(name, age)
        B.__init__(self, name, job)