Advanced
Python
Q74 / 101
What does __new__ do and when would you override it?
Correct! Well done.
Incorrect.
The correct answer is B) __new__ is called before __init__ and creates the instance; override it to control instance creation, e.g., for singletons or immutable types
B
Correct Answer
__new__ is called before __init__ and creates the instance; override it to control instance creation, e.g., for singletons or immutable types
Explanation
__new__(cls) allocates and returns a new instance. You override it when subclassing immutable types (like int or str) or implementing singleton patterns.
Progress
74/101