🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreeClass Constructor Python: How __init__() Works

A Python class needs a way to give each new object its starting values. The __init__ method receives arguments from a class call and assigns the new instance its starting state.
I’ll show how to initialize an object with __init__ and pass initialization through a subclass.
TL;DR
A Python class call creates an instance, then its __init__ method assigns that instance its starting state.
- Define __init__(self, …) when each new object needs values that belong to that object.
- Python supplies self during the call, so pass only the other arguments to ClassName(…).
- Use one __init__ with defaults or named class methods for alternate input routes.
What Is a Python Class Constructor?
In everyday Python, developers often call __init__ the constructor because it accepts the class-call arguments and sets the new instance’s initial state.
For ordinary application classes, keep __new__ inherited because custom instance creation is needed for special cases such as immutable type subclasses.
| Part | Role | What to remember |
|---|---|---|
| Class call, such as Report(…) | Starts instantiation | The caller receives the resulting object. |
| __new__(cls, …) | Creates the instance | Usually inherited. Custom implementations handle special creation needs. |
| __init__(self, …) | Initializes the instance | Assign starting attributes and return None. |
The first __init__ parameter is conventionally named self and refers to the instance, which Python supplies automatically, so Report(“Quarterly”) passes only the title. See the AskPython guide to Python classes and objects and its explanation of the self variable for those two basics.
How to Initialize Objects With a Class Constructor Step by Step
Put the values an instance needs in __init__, then call the class with those values. I use a named class method for the alternate label input because the run showed it can send parsed values through the same initializer.
Step 1: Define __init__ and create the instance
Each Report receives a title and may receive a status. The default keeps a new report in draft. The from_label class method accepts a different input shape, splits it into fields, then calls cls(…) so the regular initializer still sets the attributes.
class Report:
def __init__(self, title, status="draft"):
self.title = title
self.status = status
@classmethod
def from_label(cls, label):
title, status = label.split(":")
return cls(title, status)
regular = Report("Quarterly")
alternate = Report.from_label("Release:ready")
print(f"{regular.title}: {regular.status}")
print(f"{alternate.title}: {alternate.status}")
Run the file with this command:
python3 class_constructor_demo.py
Quarterly: draft
Release: ready

I ran python3 class_constructor_demo.py and got “Quarterly: draft” and “Release: ready.” The first call uses the default status, while the factory passes its parsed status into the same __init__ method.
Step 2: Pass initialization through a subclass
A child without its own __init__ inherits the base method, while an override replaces it and must call super().__init__(…) when the base attributes are still needed.
class Record:
def __init__(self, key):
self.key = key
class InheritsInitializer(Record):
pass
class ReplacesInitializer(Record):
def __init__(self, key):
self.local_key = key
class CallsBaseInitializer(Record):
def __init__(self, key):
super().__init__(key)
inherited = InheritsInitializer("item-1")
replaced = ReplacesInitializer("item-2")
chained = CallsBaseInitializer("item-3")
print(f"Inherited initializer: {inherited.key}")
print(f"Override skipped base: {hasattr(replaced, 'key')}")
print(f"super() forwarded: {chained.key}")
Run the comparison with:
python3 constructor_inheritance_probe.py
Inherited initializer: item-1
Override skipped base: False
super() forwarded: item-3

I ran python3 constructor_inheritance_probe.py and got False only for the override that skipped the base call. I use super() here because the same check shows the base key is present when initialization is forwarded.
In multiple inheritance, super() follows Python’s method resolution order, the order used to find methods across a class hierarchy. It advances to the next implementation in that order rather than selecting a named parent, so classes must cooperate on argument handling when they share that design.
Constructor Errors and Edge Cases
Common initializer problems come from a missing required argument, a replaced base initializer or a mistaken return value. The error message and the class definition show which case needs attention.
Check a required argument before using it
Ticket requires a title, so calling Ticket() without one fails before the body of __init__ can assign self.title. The example catches the exception only to print its exact message. Supply the title or define a suitable default to prevent it.
class Ticket:
def __init__(self, title):
self.title = title
try:
Ticket()
except TypeError as error:
print(f"{type(error).__name__}: {error}")
Run the file with:
python3 constructor_missing_argument.py
TypeError: Ticket.__init__() missing 1 required positional argument: 'title'

I ran python3 constructor_missing_argument.py and got “TypeError: Ticket.__init__() missing 1 required positional argument: ‘title’.” I check the named argument first because this result identified title before the initializer body ran.
| Case | Symptom | Fix |
|---|---|---|
| No custom __init__ | The class uses inherited initialization. The object default accepts no extra arguments. | Define __init__ only when the instance needs custom starting state. |
| Second __init__ definition | The later definition replaces the earlier method with the same name. | Use defaults or a named @classmethod such as from_label. |
| Returning a value from __init__ | Python raises TypeError if the method returns something other than None. | Leave out return, or return None explicitly. |
| Mutable default such as items=[] | Instances can share the same list because the default is created once. | Use None, then create a new list inside __init__. |
Defining two methods named __init__ does not overload them by argument count because the class keeps the later definition under that name.
Because Python creates items=[] once when it defines the method, instances can share that list, so use items=None and allocate [] inside __init__ when a call supplies no list. The Python tutorial on default argument values documents this behavior.
Conclusion
Require fields every instance needs, and provide defaults only when an omitted value still produces a usable object.
- Python data model: object.__new__ and object.__init__
- Python tutorial: classes and inheritance
- Python tutorial: default argument values
- AskPython: Python classes and objects
- AskPython: the self variable
FAQ
A class can have one __init__ method, and it is optional when the class needs no custom instance state.
Can a Python class have multiple constructors?
A class has one method named __init__. Use default arguments or named @classmethod factories for alternate ways to create an instance.
Does every Python class need an __init__ method?
No. A class can inherit an initializer or use the default object initializer when no custom starting state is needed.
How do I call a parent class constructor in Python?
When a subclass defines __init__ and still needs its base class state, call super().__init__(…) with the base initializer arguments.


