Repaso
EspaƱol
PythonAdvancedPY-34

What is the difference between __new__ and __init__?

Options

  1. They are aliases, so defining either one has the same effect
  2. __new__ creates and returns the instance; __init__ fills it in (Correct option)
  3. __init__ runs first and __new__ runs after it
  4. __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.

Key terms

Practice this question in Repaso