init And super With Inheritance
__init__ and super() with Inheritance in Python
Python is an object-oriented language where everything revolves around classes and objects. To understand how objects are created and initialized in an inheritance hierarchy, it is essential to understand init, inheritance, and super() together, as they work as a single system.
Universal Parent Class: object
In Python, every class is a child of the built-in object class, even if it is not explicitly mentioned.
class A:
passInternally, Python treats it as:
class A(object):
passThis is why all Python classes have access to methods like:
__init____str____eq____hash__
Inheritance and Method Availability
When a class inherits from another class, it automatically gains access to all non-private methods of the parent class.
class A(object):
def f1(self):
print("f1 works")
obj1 = A()
obj1.f1()Output
f1 worksHere:
Ainherits fromobjectf1()is accessed directly from classA
How __init__ Works with Inheritance?
When an object of a child class is created, Python follows this lookup order:
- Python looks for
__init__in the child class - If not found, it searches in the parent class
- If found, it is executed

Case 1: Child Class Does NOT Have __init__
class A:
def __init__(self):
print("in A init")
class B(A):
pass
obj = B()Output
in A initExplanation
Bdoes not define__init__- Python automatically calls
A.__init__()
Case 2: Child Class HAS Its Own __init__
When a child class defines __init__, it overrides the parent’s __init__.
class A:
def __init__(self):
print("in A init")
class B(A):
def __init__(self):
print("in B init")
obj = B()Output
in B initParent
__init__is not executed automatically.
Introducing super()
What is super()?
super()returns a proxy object of the parent class- It allows access to parent class methods
- It follows Python’s Method Resolution Order (MRO)

Calling Parent Methods Using super()
Parent methods can be accessed using:
self.method_name()super().method_name()
Both work, but super() is preferred for:
- Clarity
- Multiple inheritance safety
Example: Calling Parent __init__ Using super()
class A:
def __init__(self):
print("in A init")
def f1(self):
print("f1 works")
class B(A):
def __init__(self):
super().__init__()
print("in B init")
def f2(self):
super().f1()
print("f2 works")
obj1 = B()
obj1.f2()Output
in A init
in B init
f1 works
f2 worksExplanation
When obj1 = B() is executed:
- Python searches for
__init__inB - Finds it → executes
B.__init__ super().__init__()callsA.__init__- Parent initialization runs
- Child initialization completes
Summary
- Every Python class inherits from
object, enabling built-in behavior and methods. - Inheritance allows child classes to reuse parent methods and functionality.
- Defining
__init__in a child class overrides the parent’s initialization. super()is required to execute parent initialization and access parent methods safely.- Proper use of
__init__andsuper()is essential for clean, scalable object-oriented design in Python.
Written By: Muskan Garg
How is this guide?
Last updated on
