What are __init__ and self in a Python class?
Reviewed by Gurusankar M.
Short Answer
`__init__` is the initializer that runs when you create an object — it sets up instance attributes. `self` is the reference to the current instance, passed automatically as the first parameter of every instance method, so methods can read/write that object's own data.
On this page
Concept Made Simple
Coffee Chat Question
“What are __init__ and self in a Python class?”
Remember It Faster
Mind Map Answer
- class
- blueprint for objects
- __init__
- runs on creation, sets attributes
- self
- the current instance
- instance vs class attr
- per-object vs shared
Learn by Doing
Hands-on Keyboard
class Account:
def __init__(self, owner, balance=0):
self.owner = owner # instance attribute
self.balance = balance
def deposit(self, amount):
self.balance += amount
return self.balance
a = Account("Guru", 100)
print(a.deposit(50))150
Think Beyond the Expected
What If?
What happens if you forget `self` as the first method parameter?
Calling the method raises a TypeError about arguments, because Python passes the instance as the first positional argument automatically — the method needs a parameter (conventionally `self`) to receive it. Without it, the counts don't match. `self` isn't a keyword, just a strong convention.
Real World
Classes model real entities — User, Order, Account — bundling their data and behavior; `__init__` + `self` are the first things every Python developer uses when structuring an app's domain objects.
Interviewer's Expectation
Keywords they're listening for:
- __init__ initializes
- self = current instance
- instance attributes via self
- auto-passed first arg
- class vs instance attribute
Common Mistakes
- Forgetting self in method signatures
- Using a mutable class attribute as if it were per-instance
- Doing heavy work in __init__
Best Practices
- Set all instance state in __init__
- Use self for per-object data; class attrs for shared constants
- Add __repr__ for debuggable objects
Follow-up Questions
- Instance vs class attribute — where does each live?
- What is __str__ / __repr__ for?
- What are @classmethod and @staticmethod?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: OOP (Python) Interview question: "What are __init__ and self in a Python class?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair