Python Dunder New Explained — How Instance Objects Are Created

Python Dunder New Explained

When you call class in Python, you might think __init__ is where everything begins. But there’s a step that happens before it — one that most Python developers never notice. That step is __new__.

__new__ is a static method in Python that is responsible for creating and returning a new instance of a class before __init__ runs. It receives the class itself as the first argument (cls), allocates memory for the new object via super().__new__(cls), and returns that object. If it does not return a valid instance, __init__ is never called.

Understanding __new__ means understanding what Python is really doing every time you instantiate a class. Let’s go step by step.

1.Creating Instance Object From Empty Class

Python
class Person:
    pass

p = Person()

print(p) # instance object
print(id(p)) # id of instance object in memory
print(p.__dict__) # object namespace

Output