What is the purpose of the __init__ method in Python?
Correct answer
C. Initialize an object
14 views
C. Initialize an object
14 views
__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.
Not sure why the answer is C? Ask here and get an explanation.