AI engineering glossary · Python advanced
What is __new__?
__new__: The special method that actually creates and returns a new object before __init__ initialises it. It is rarely overridden, mainly for immutable types or controlling instance creation, as in singletons.
__new__: an example
def __new__(cls): if not cls._inst: cls._inst = super().__new__(cls); return cls._inst reuses one instance.
Related terms
- __init__
- Constructor
- Singleton
- Metaclass
More Python advanced terms
Where you learn it
__new__ is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.