Constructors in Python — a practical guide to Python __init__ constructor with clear examples you can reuse in real projects.
Python Tutorial Series (46/95). Prefer one article? Read the complete Python tutorial.
Short description
`__init__` runs when you create an object. Set required attributes there.
__init__ example
class BankAccount:
def __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
acc = BankAccount('Asha', 1000)
print(acc.owner, acc.balance)