Last reviewed
Correct answer: A. It's called automatically when a new instance is created, to set up initial attributes
Explanation
The word people reach for here is constructor, and that habit is what this question should break. The initialiser does not build your object; it is handed one that already exists and given the chance to furnish it. The data model is precise about the ordering: it is "Called after the instance has been created (by __new__()), but before it is returned to the caller." The tutorial agrees: "When a class defines an __init__() method, class instantiation automatically invokes __init__() for the newly created class instance."
Two consequences follow. It must not hand a value back, because substituting or reusing an object is the job of __new__, not of the initialiser. And its default arguments are evaluated once, when the function is defined: "The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes." So a default of an empty list is shared by every instance ever created; pass None and build it in the body.
The distractors describe a destructor, a shutdown hook, and a rule about built-ins. None runs at instantiation.
Sources
“Called after the instance has been created (by __new__()), but before it is returned to the caller.”
“When a class defines an __init__() method, class instantiation automatically invokes __init__() for the newly created class instance.”
“The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes.”
Practise 3 questions on this topic
Take Python OOP — Timed Test (3 questions) — scored instantly, explanation for every question, no login.