__new__ vs __init__ in Python

If you’re choosing between __new__ and __init__ for a class, pick __init__ nearly every time. That’s the heart of __new__ vs __init__ in Python: __new__ creates and returns the object, and __init__ fills in its attributes.

Override __new__ only when creation itself must change, like subclassing float or str, returning a cached object, or building a singleton.

In this tutorial, I’ll run both on one small online-store order and show where each one wins. Every output below came from a real run on Python 3.12.5.

__new__ vs __init__ at a Glance

Feature__new____init__
JobCreates the objectSets up the object
RunsFirstSecond, only on what __new__ returned
First argumentcls (the class)self (the new object)
Must returnThe object (any object)None
Can change immutable valuesYesNo
Runs on copy.copy() / pickleYesNo
Typical usefloat/str subclasses, singletons, cachingAlmost every class

The sample is an Order for Megan Bowen totaling $149.99. If you only need the setup half, the __init__ method in Python covers it in depth.

Which Runs First: __new__ or __init__?

Same Order class for Megan Bowen. I added a print to each method so you can watch the hand-off:

class Order:
    def __new__(cls, *args):
        print("1. __new__ gets the class:", cls.__name__)
        obj = super().__new__(cls)      # create the empty object
        return obj

    def __init__(self, customer, total):
        print("2. __init__ gets the object:", type(self).__name__)
        self.customer = customer        # fill in its attributes
        self.total = total


order = Order("Megan Bowen", 149.99)
print(f"{order.customer}: ${order.total:,.2f}")

Output:

1. __new__ gets the class: Order
2. __init__ gets the object: Order
Megan Bowen: $149.99
VS Code output of a Python Order class printing that __new__ runs before __init__
__new__ prints first with the class, then __init__ prints with the finished object.

How does this code work?

Order(...) calls Order.__new__(Order, ...). It asks object.__new__ for an empty object and returns it.

Python then calls __init__ on that object with the same arguments. The full constructor story is in constructors in Python.

Why Can’t __init__ Change an Immutable Type Like float?

Now the order total gets its own Price type that rounds to cents. Here’s the same rounding tried in each method:

class PriceInit(float):
    def __init__(self, value):
        self = round(value, 2)          # rebinds a local name only


class Price(float):
    def __new__(cls, value):
        return super().__new__(cls, round(value, 2))


print("__init__ version:", PriceInit(149.987))
print("__new__ version: ", Price(149.987))
print("Tax at 8.25%:    ", round(Price(149.987) * 0.0825, 2))

Output:

__init__ version: 149.987
__new__ version:  149.99
Tax at 8.25%:     12.37
VS Code output of a Python float subclass where __init__ fails to round the value and __new__ rounds it to 149.99
The __init__ version keeps 149.987; the __new__ version stores 149.99.

How does this code work?

A float gets its value when it’s created, and it can’t change afterward. By the time __init__ runs, 149.987 is locked in, so self = ... just rebinds a local name.

__new__ runs before the value exists, so it passes the rounded number to float.__new__. The same rule applies to str, int and tuple, as explained in mutable vs immutable in Python.

When Does Python Skip __init__?

Python calls __init__ only when __new__ returns an instance of the class. Here a $0.00 order is rejected, and one order gets copied:

import copy


class Order:
    def __new__(cls, *args):            # copy calls it with no args
        if args and args[1] <= 0:
            return None                 # not an Order
        return super().__new__(cls)

    def __init__(self, customer, total):
        print(f"   __init__ runs for {customer}")
        self.customer, self.total = customer, total


print("A:", Order("Megan Bowen", 149.99).total)
print("B:", Order("Alex Wilber", 0.00))
print("copy.copy():")
clone = copy.copy(Order("Adele Vance", 89.50))
print("clone total:", clone.total)

Output:

   __init__ runs for Megan Bowen
A: 149.99
B: None
copy.copy():
   __init__ runs for Adele Vance
clone total: 89.5
VS Code output showing Python skipping __init__ when __new__ returns None and when copy.copy clones an object
The $0.00 order returns None with no __init__ line, and copy.copy() clones without calling __init__.

How does this code work?

Alex Wilber’s order returns None, which isn’t an Order, so __init__ never prints.

copy.copy() and pickle also skip __init__: they call __new__(cls) with no arguments (hence *args), then copy the attributes over. Important: don’t put must-run logic only in __init__ if objects get copied. A classmethod is the cleaner way to build objects other ways.

Singleton Pattern: Why Does __init__ Run Again?

A singleton is a class with only one object. This store config caches it in __new__, and the Austin store sets an 8.25% tax rate:

class StoreConfig:
    _instance = None

    def __new__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
        return cls._instance

    def __init__(self, tax_rate=0.0):
        self.tax_rate = tax_rate        # runs on EVERY call


austin = StoreConfig(tax_rate=0.0825)
later = StoreConfig()
print("Same object:", austin is later)
print("Tax rate:   ", austin.tax_rate)

Output:

Same object: True
Tax rate:    0.0
VS Code output of a Python singleton where the second call re-runs __init__ and resets the tax rate to 0.0
Both calls return the same object, but the second call’s __init__ resets the tax rate to 0.0.

How does this code work?

__new__ returns the cached object, and because it’s an instance of the class, Python calls __init__ on it again. The default tax_rate=0.0 wipes out 0.0825.

The fix is a guard at the top of __init__:

    def __init__(self, tax_rate=0.0):
        if hasattr(self, "tax_rate"):   # already set up
            return
        self.tax_rate = tax_rate

Output:

Same object: True
Tax rate:    0.0825

Now the tax rate stays 0.0825. For one-instance classes, a module-level object is often simpler; the metaclass singleton avoids the re-run too.

Common TypeError Messages with __new__ and __init__

Same Order class, plus two helpers. Each one breaks a rule:

class Order:
    def __new__(cls, *args):
        return super().__new__(cls, *args)   # passes the args on

    def __init__(self, customer, total):
        self.customer, self.total = customer, total


class Receipt:
    def __init__(self, total):
        self.total = total
        return total                         # __init__ must return None


class Coupon:                                # no __init__ at all
    pass


for make in (lambda: Order("Megan Bowen", 149.99),
             lambda: Receipt(149.99),
             lambda: Coupon("SAVE10")):
    try:
        make()
    except TypeError as err:
        print("TypeError:", err)

Output:

TypeError: object.__new__() takes exactly one argument (the type to instantiate)
TypeError: __init__() should return None, not 'float'
TypeError: Coupon() takes no arguments
VS Code output of three Python TypeError messages from __new__ passing arguments, __init__ returning a value and a class with no __init__
Three real TypeError messages: extra arguments to object.__new__, __init__ returning a value, and a class without __init__.

When you override __new__, call super().__new__(cls) with no extra arguments; object.__new__ rejects them. __init__ must return None.

A class with neither method takes no arguments. The wording matched on Python 3.11, 3.12 and 3.14. For empty classes, see empty constructors in Python.

When to Use __new__ Instead of __init__

  • Setting attributes or validating input: __init__.
  • Subclassing float, int, str or tuple and changing the value: __new__.
  • Returning a cached or shared object (singleton, interning): __new__, with a guard in __init__.
  • Several ways to build an object: neither; use classmethod alternative constructors.

So __new__ decides which object you get, and __init__ decides what’s in it.

These related class guides pick up from here:

Frequently asked questions

Is __new__ or __init__ the constructor in Python?

Strictly,