×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

How to Explicitly Pass Class and Instance to super() in Python

By IncludeHelp Last updated : February 21, 2024

Problem statement

Write Python code to explicitly pass class and instance to super().

Explicitly passing class and instance to super()

You can explicitly pass the current class and instance as arguments to change the behavior of super() method. Consider the below given code.

Python Code to Explicitly Pass Class and Instance to super()

# Create a parent class
class Class1:
    def __init__(self):
        print("Class1 constructor")

# Create an intermediate class
class Class2(Class1):
    def __init__(self):
        super(Class2, self).__init__()
        print("Class2 constructor")

# Create a child class
class Class3(Class2):
    def __init__(self):
        super(Class3, self).__init__()
        print("Class3 constructor")

# Main code
child_instance = Class3()

Output

The output of the above code is:

Class1 constructor
Class2 constructor
Class3 constructor

To understand the above program, you should have the basic knowledge of the following Python topics:

 
 
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.