Python classes and objects

A class defines behavior for instances. Calling the class creates an object and invokes __init__ to initialize it. self refers to the instance whose method is running.

Python
class Counter:
    def __init__(self):
        self.value = 0
    def increment(self):
        self.value += 1

first = Counter()
second = Counter()
first.increment()
first.increment()
print(first.value, second.value)
assert second.value == 0
Read the full lesson