1. Home
  2. Data Science
  3. Python
  4. What is the purpose of the __init__ method in Python?

Added 25 Jan 2024

What is the purpose of the __init__ method in Python?

  1. Initialize a variable
  2. Initialize a class
  3. Initialize an object Correct answer
  4. Initialize a module

Correct answer

C. Initialize an object

14 views

MCQSEXAM

Explanation

__init__ is used to initialise an object. Python calls it automatically right after a new instance is created, and it sets the object's starting attributes: def __init__(self, name): self.name = name.

It is often called the constructor, although strictly __new__ creates the object and __init__ only initialises it.

Practise more Computer Science MCQs with answers and explanations on MCQsExam.com.

Doubts & discussion

Not sure why the answer is C? 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