GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python super() - GeeksforGeeks Python super()Last Updated : 18 Mar, 2026 In Python, super() function is used to call methods from a parent (superclass) inside a child (subclass). It allows to extend or override inherited methods while still reusing the parent's functionality. Let's understand how super() works with an example where a child class calls a method from its parent class.
Output This is Parent class method This is Child class method Explanation:
Syntax
Return: Return a proxy object which represents the parent's class. Why Use super()?
Initialize Parent Attributes with super()In this example, child class uses super() to call the parent class constructor, allowing it to initialize inherited attributes while also adding its own new attribute.
Output 101 Olivia [email protected] Explanation:
Effect of Using and Not Using super()Example 1: In this example, child class overrides the constructor but does not call the parent constructor, which results in missing initialization of inherited attributes.
Output
Example 2: In this example, super() is used inside the child class constructor to properly call the parent constructor, ensuring that inherited attributes are initialized correctly.
Output James 103 Explanation:
Using super() in Multilevel InheritanceIn a multilevel inheritance setup, super() ensures that each parent class constructor is executed in the correct sequence. It follows Python’s Method Resolution Order (MRO) to maintain a consistent and predictable flow of initialization.
Output Dog cannot swim Dog cannot fly Dog is a mammal Explanation:
Related Articles:Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |