In Python’s data model, when is __new__ called versus __init__, and what must __new__ return?

Python Professional Hard

Python Professional — Hard

In Python’s data model, when is __new__ called versus __init__, and what must __new__ return?

Key points

  • __new__ creates or returns an instance
  • __init__ initializes attributes
  • __new__ is called before __init__
  • __init__ is only called if the instance is of the class

Ready to go further?

Related questions