What is the difference between __new__ and __init__?
Options
- They are aliases, so defining either one has the same effect
__new__creates and returns the instance;__init__fills it in (Correct option)__init__runs first and__new__runs after it__new__is only used when you write a metaclass
Answer
__new__ creates and returns the instance; __init__ initializes it
Why
Creating an object happens in two steps: __new__ builds the empty object and returns it, then __init__ fills it with starting values.
You rarely need __new__. It is used when you must control creation itself: subclassing immutable types like int or str, or returning an existing (cached) object.
Remember
__new__ creates, __init__ initializes.