1. Home
  2. Data Science
  3. Python
  4. What is the purpose of the super() function in Python?

Added 25 Jan 2024

What is the purpose of the super() function in Python?

  1. Call a parent class method Correct answer
  2. Call a child class method
  3. Create an instance of a class
  4. Access global variables

Correct answer

A. Call a parent class method

14 views

MCQSEXAM

Explanation

super() is used to call a method of the parent class from a child class. The commonest use is super().__init__() inside a subclass constructor, so the parent's initialisation still runs.

It avoids hard-coding the parent's name and follows the method resolution order, which matters with multiple inheritance.

For more solved questions like this one, see Computer Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs