super()

super() returns access the base class methods

By using super() we need not use the name of the base class explicitly.
It is useful in multiple inheritance
Read more on inheritance

Example with inheritance

class animals():
    home='Jungle' #class attribute
#instance attributes
    def __init__(self,name,height):
        self.name= name
        self.height=height
    def legs(self):
        print("has four legs")
    
class wild(animals):
    def __init__(self,name,weight):
        self.name=name
        self.weight=weight
        #animals.__init__(self,name,5)
        super().__init__(name,5)   
    
tiger=wild('Tom',3) # object is created. 
print(tiger.weight) # 3
print(tiger.height) # 5   
tiger.legs()        # has four legs
In above code by using super() we can access the methods of the base class animals(). While not using super() we can access the methods of parent class animals() by using the line animals.__init__(self,name,5).

By using super() we can avoid explicit use of base class name. The advantage is while using multilevel inheritance.

Multiple inheritance

class animals():
    home='Jungle' #class attribute
#instance attributes
    def __init__(self):
        self.name= 'Alex'
        self.height=2
    def legs(self):
        print("has four legs")
class carnivores(animals):
    def __init__(self):
        self.food='flseh'
        super().__init__()
        
class wild(carnivores):
    def __init__(self):
        self.weight=5
        #animals.__init__(self,name,5)
        super().__init__()   
    
tiger=wild()    # object is created. 
print(tiger.weight) # 3
print(tiger.food)   # flesh 
print(tiger.name)   # Alex
print(tiger.height) # 2 
tiger.legs()        # has four legs


All Built in Functions in Python locals() dir() ord()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer