Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Print Objects of a Class in Python
Next article icon

Call Parent class method – Python

Last Updated : 14 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In object-oriented programming in Python, the child class will inherit all the properties and methods of the parent class when the child class inherits the parent class. But there may be some cases when the child class has to call the methods of the parent class directly. Python has an easy and effective solution to call the parent class methods and both parent and child classes can work together without any problems. This is especially useful when we override a method in the child class but still want to use the parent class’s version of the method.

Example:

Python
class cls:   	def __init__(self, fname, mname, lname):  		self.firstname = fname  		self.middlename = mname  		self.lastname = lname  		 	def print(self):  		print(self.firstname, self.middlename, self.lastname)   x = cls("Geeks", "for", "Geeks")  x.print()  

Output
Geeks for Geeks 

Explanation: This code defines a class cls with a constructor to initialize firstname, middlename and lastname. The print method outputs the full name. An object x is created with names “Geeks”, “for” and “Geeks” and the print method displays “Geeks for Geeks”.

Syntax for Calling Parent Class Method in Python

There are a couple of ways we can call the parent class method in Python, depending on whether we’re using super() or directly referencing the parent class.

1. Using super()

The super() function allows us to call methods from the parent class. The syntax is:

super().method_name(args)

2. Calling Parent Class Method Directly

Alternatively, we can call the parent class method explicitly by referencing the class name directly.

ParentClass.method_name(self, args)

Understanding Inheritance in Python

In simpler terms, inheritance is the concept by which one class (commonly known as child class or sub class) inherits the properties from another class (commonly known as Parent class or super class). But have we ever wondered about calling the functions defined inside the parent class with the help of child class? Well this can done using Python. we just have to create an object of the child class and call the function of the parent class using dot(.) operator.

Example:

Python
class Parent:   	def show(self):  		print("Inside Parent class")    class Child(Parent):  	 	def display(self):  		print("Inside Child class")   obj = Child()  obj.display()    obj.show()  

Output
Inside Child class Inside Parent class 

Explanation: This code defines a parent class Parent with a method show that prints “Inside Parent class.” A child class Child inherits from Parent and has its own method display that prints “Inside Child class.” An object obj of the Child class is created and both display and show methods are called, printing “Inside Child class” followed by “Inside Parent class.”

Calling Parent class method after method overriding

Method overriding is an ability of any object-oriented programming language that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. Parent class methods can also be called within the overridden methods. This can generally be achieved by two ways.

Using Classname

Parent’s class methods can be called by using the Parent classname.method inside the overridden method.

Example:

Python
class Parent():  	 	def show(self):  		print("Inside Parent")  		 class Child(Parent):  	 	def show(self):  		 		Parent.show(self)  		print("Inside Child")  		 obj = Child()  obj.show()  

Output
Inside Parent Inside Child 

Explanation: This code defines a Parent class with a method show that prints “Inside Parent.” The Child class inherits from Parent and overrides the show method. Inside the child class’s show method, it calls the parent class’s show method using Parent.show(self) and then prints “Inside Child.” An object obj of the Child class is created and the show method is called, printing “Inside Parent” followed by “Inside Child.”

Using Super()

Python super() function provides us the facility to refer to the parent class explicitly. It is basically useful where we have to call superclass functions. It returns the proxy object that allows us to refer parent class by ‘super’.

Example 1:

Python
class Parent():  	 	def show(self):  		print("Inside Parent")  		 class Child(Parent):  	 	def show(self):  		  		super().show()  		print("Inside Child")   obj = Child()  obj.show()  

Output
Inside Parent Inside Child 

Explanation: This code defines a Parent class with a show method. The Child class overrides the show method and calls the parent’s show method using super(). When obj.show() is called, it prints “Inside Parent” followed by “Inside Child.”

Example 2:

Python
class GFG1:  	def __init__(self):  		print('HEY !!!!!! GfG I am initialised(Class GEG1)')  	 	def sub_GFG(self, b):  		print('Printing from class GFG1:', b)  	 # class GFG2 inherits the GFG1  class GFG2(GFG1):  	def __init__(self):  		print('HEY !!!!!! GfG I am initialised(Class GEG2)')  		super().__init__()  	 	def sub_GFG(self, b):  		print('Printing from class GFG2:', b)  		super().sub_GFG(b + 1)  	 # class GFG3 inherits the GFG1 ang GFG2 both  class GFG3(GFG2):  	def __init__(self):  		print('HEY !!!!!! GfG I am initialised(Class GEG3)')  		super().__init__()  	 	def sub_GFG(self, b):  		print('Printing from class GFG3:', b)  		super().sub_GFG(b + 1)  	 	 # main function  if __name__ == '__main__':  	 	gfg = GFG3()    	gfg.sub_GFG(10)  

Output

HEY !!!!!! GfG I am initialised(Class GEG3)
HEY !!!!!! GfG I am initialised(Class GEG2)
HEY !!!!!! GfG I am initialised(Class GEG1)
Printing from class GFG3: 10
Printing from class GFG2: 11
Printing from class GFG1: 12

Explanation: This code demonstrates multiple inheritance where GFG2 and GFG3 inherit from GFG1. Each class overrides the sub_GFG method and super() is used to call the parent class method. When an object of GFG3 is created and sub_GFG(10) is called, it prints messages from all three classes, showcasing method resolution in multiple inheritance.

Related Articles:

  • Python OOPs Concepts
  • Python Classes and Objects
  • Inheritance in Python
  • Python Functions
  • Method Overriding in Python
  • Python super()


Next Article
Print Objects of a Class in Python

P

priyanshid1
Improve
Article Tags :
  • Python
  • python-oop-concepts
Practice Tags :
  • python

Similar Reads

  • classmethod() in Python
    The classmethod() is an inbuilt function in Python, which returns a class method for a given function. This means that classmethod() is a built-in Python function that transforms a regular method into a class method. When a method is defined using the @classmethod decorator (which internally calls c
    8 min read
  • Python Metaclass __new__() Method
    In Python, metaclasses provide a powerful way to customize the creation of classes. One essential method in metaclasses is __new__, which is responsible for creating a new instance of a class before __init__ is called. Understanding the return value of __new__ in metaclasses is crucial for implement
    3 min read
  • Print Objects of a Class in Python
    In object-oriented programming (OOP), an object is an instance of a class. A class serves as a blueprint, defining the structure and behavior of objects, while an instance is a specific copy of the class with actual values. When an object is created, the class is said to be instantiated. All instanc
    4 min read
  • Command Method - Python Design Patterns
    Command Method is Behavioral Design Pattern that encapsulates a request as an object, thereby allowing for the parameterization of clients with different requests and the queuing or logging of requests. Parameterizing other objects with different requests in our analogy means that the button used to
    3 min read
  • Python | Decimal max() method
    Decimal#max() : max() is a Decimal class method which compares the two Decimal values and return the max of two. Syntax: Decimal.max() Parameter: Decimal values Return: the max of two. Code #1 : Example for max() method # Python Program explaining # max() method # loading decimal library from decima
    2 min read
  • Python | Decimal is_normal() method
    Decimal#is_normal() : is_normal() is a Decimal class method which checks whether the Decimal value is a normal finite number. Syntax: Decimal.is_normal() Parameter: Decimal values Return: true - if the Decimal value is a normal finite number; otherwise false Code #1 : Example for is_normal() method
    2 min read
  • Python | Decimal min() method
    Decimal#min() : min() is a Decimal class method which compares the two Decimal values and return the min of two. Syntax: Decimal.min() Parameter: Decimal values Return: the min of two. Code #1 : Example for min() method # Python Program explaining # min() method # loading decimal library from decima
    2 min read
  • Define and Call Methods in a Python Class
    In object-oriented programming, a class is a blueprint for creating objects, and methods are functions associated with those objects. Methods in a class allow you to define behavior and functionality for the objects created from that class. Python, being an object-oriented programming language, prov
    3 min read
  • Python | Decimal logb() method
    Decimal#logb() : logb() is a Decimal class method which returns the adjusted exponent of the Decimal value. Syntax: Decimal.logb() Parameter: Decimal values Return: the adjusted exponent of the Decimal value. Code #1 : Example for logb() method # Python Program explaining # logb() method # loading d
    2 min read
  • Python - Access Parent Class Attribute
    A class is a user-defined blueprint or prototype from which objects are created. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences