Skip to content

__init__

In Python, .__init__() is the special method that sets up a new object right after its class creates it, giving each instance its starting attribute values. When you call a class like Account("Ada"), Python builds the empty object with .__new__() first, then hands it to .__init__() as self along with the arguments from the call. Assigning to self inside that special method is what gives the instance its attributes.

That two-step split is why .__init__() isn’t a constructor in the sense that C++ or Java uses the word. It doesn’t create the object, and it must return None. Returning any other value raises a TypeError.

When a class inherits from a parent that defines its own .__init__(), the child has to call it explicitly with super().__init__(). Python doesn’t chain the calls for you, so skipping it leaves the parent’s share of the instance uninitialized.

Example

Say you’re modeling a bank account, and every account needs an owner and a balance before anyone can use it:

Language: Python
>>> class Account:
...     def __init__(self, owner, balance=0):
...         self.owner = owner
...         self.balance = balance
...

>>> account = Account("Ada", 100)
>>> account.owner
'Ada'
>>> account.balance
100

>>> Account("Grace").balance
0

Python runs .__init__() once per instance, immediately after Account("Ada", 100) produces the object. The two assignments attach .owner and .balance to that one account, so a second account gets its own separate values. Because balance carries a default parameter value, the last call still returns a fully initialized account without passing a second argument.

Step through that same call below to watch each stage in turn, from the empty object that .__new__() hands over to the attributes each assignment attaches:

Interactive diagram — enable JavaScript to view.
Python Classes: The Power of Object-Oriented Programming

Tutorial

Python Classes: The Power of Object-Oriented Programming

Learn how to define and use Python classes to implement object-oriented programming. Dive into attributes, methods, inheritance, and more.

intermediate best-practices 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 Sept. 24, 2026