__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:
>>> 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:
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Object-Oriented Programming (OOP) in Python (Tutorial)
- Supercharge Your Classes With Python super() (Tutorial)
- A Conceptual Primer on OOP in Python (Course)
- Python Basics Exercises: Object-Oriented Programming (Course)
- Object-Oriented Programming in Python vs Java (Tutorial)
- What Is Python's __init__.py For? (Tutorial)
- Class Concepts: Object-Oriented Programming in Python (Course)
- Inheritance and Internals: Object-Oriented Programming in Python (Course)
- Python Classes - The Power of Object-Oriented Programming (Quiz)
- Intro to Object-Oriented Programming (OOP) in Python (Course)
- Object-Oriented Programming (OOP) in Python (Quiz)
- Supercharge Your Classes With Python super() (Course)
- Supercharge Your Classes With Python super() (Quiz)
- Python vs Java: Object Oriented Programming (Course)
- What Does Python's __init__.py Do? (Course)
- What Is Python's __init__.py For? (Quiz)
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