English

Explain the significance of super() function.

Advertisements
Advertisements

Question

Explain the significance of super() function.

Code Writing
Explain
Advertisements

Solution

super() is used in a derived class to access methods of its parent class, especially the parent constructor.

class Student(Person):
    def __init__(self, name, roll_no):
        super().__init__(name)
        self.roll_no = roll_no

It avoids repeating parent-class code and is especially useful in multilevel inheritance.

shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 78]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 4 Inheritance
EXERCISE | Q 9. | Page 78
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×