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.

Level: advancedTopic: Python advanced

__new__: an example

def __new__(cls): if not cls._inst: cls._inst = super().__new__(cls); return cls._inst reuses one instance.

Related terms

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.