Core Concept Mastery • Python Visual Series Module
The `self` parameter is a reference to the current instance of the class. It is how a method knows which object's data to read or write. Python passes `self` automatically — you just need to include it as the first parameter.
class Counter:
def __init__(self):
self.count = 0
def increment(self):
self.count += 1
return self.count
c1 = Counter()
c2 = Counter()
print(c1.increment())
print(c1.increment())
print(c2.increment())
Counter has __init__ (sets count to 0) and increment (adds 1 and returns the new count). The key is "self" — it's how each method knows WHICH object to operate on.