🧱 Object-Oriented Python
Classes & Objects
Define your own types with state and behavior.
A class is a blueprint. An *object* is an instance of that blueprint. Use class to define one and __init__ to set up new instances.
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says woof!"
d = Dog("Rex")
print(d.bark())
self is the instance itself — always the first parameter of an instance method.