Classes and objects
A class is a blueprint for a kind of thing. An object is one actual thing built from that blueprint, with its own information inside it.
Think of it likeThe class is the recipe for a cake; each cake you bake from it is an object. Same instructions, different cakes.
You write class BankAccount: and then, indented inside it, the functions this kind of thing can do. Those functions are called methods.
The special method __init__ runs automatically whenever you make a new object, and its job is to set up the starting information. The double underscores mean Python calls it for you rather than you calling it by name.
Every method takes self as its first parameter. self means “the particular object this was called on”. When you write self.balance = 0 inside __init__, you are storing a balance on this one account, separate from every other account. When you later write account.deposit(50), Python passes that account in as self automatically — which is why you never pass it yourself.
self feels arbitrary right up until the moment it does not. The thing that makes it click, for most people, is making two objects from the same class and watching them hold different values completely independently.
Where you meet it in real softwareUsers, orders, files, network connections — anything a program treats as a thing with properties and behaviour.