Skip to content

__new__()

In Python, .__new__() is the special method that creates and returns a new instance of a class. When you call a class like Point(1, 2), Python runs .__new__() first to build the object. It then passes that object to .__init__(), which sets its starting attributes.

The method receives the class itself as its first argument, conventionally named cls, followed by the arguments from the call. It’s a static method, but Python special-cases it, so you don’t need a decorator. If it returns an instance of cls, Python calls .__init__() on that instance. If it returns anything else, Python skips .__init__() entirely, as this flow shows:

Calling Point(1, 2) creates the object first. If the result is an instance of the class, initialization runs next. Otherwise initialization is skipped.
Object Creation Always Comes First, Initialization Only Sometimes

Most classes never override .__new__() because the version inherited from object already does the job. You override it when a value must be settled at creation time, such as in a subclass of an immutable type like str, int, or tuple. By the time .__init__() runs, that value is already fixed. A metaclass also commonly overrides .__new__() to customize how classes get built.

Example

Say you’re storing product codes and want every code normalized to uppercase with no stray whitespace. Because strings are immutable, the cleanup has to happen while the object is being created:

Language: Python
>>> class ProductCode(str):
...     def __new__(cls, value):
...         return super().__new__(cls, value.strip().upper())
...

>>> code = ProductCode("  ab-123 ")
>>> code
'AB-123'
>>> isinstance(code, str)
True

The overridden .__new__() cleans up the raw text and hands the result to str.__new__() through super(), which builds the actual string object. The returned instance is both a ProductCode and a regular str, so it works anywhere a string does. An .__init__() method couldn’t do this, because the string’s characters are locked in before it runs.

Python Class Constructors: Control Your Object Instantiation

Tutorial

Python Class Constructors: Control Your Object Instantiation

In this tutorial, you'll learn how class constructors work in Python. You'll also explore Python's instantiation process, which has two main steps: instance creation and instance initialization.

intermediate python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Martin Breuss • Updated Oct. 28, 2026