Intermediate
Python
Q88 / 101
What is Python's __new__ vs __init__?
Correct! Well done.
Incorrect.
The correct answer is B) __new__ creates and returns the instance; __init__ initializes it. Override __new__ to control instance creation (e.g., singletons, immutable types)
B
Correct Answer
__new__ creates and returns the instance; __init__ initializes it. Override __new__ to control instance creation (e.g., singletons, immutable types)
Explanation
__new__(cls) is called first and must return an instance. __init__(self) is called on the returned instance. Subclassing int or str requires overriding __new__.
Progress
88/101