Classes
A class is a blueprint for objects. __init__ runs when an object is created, self is the object itself:
class Dog:
def __init__(self, name):
self.name = name # attribute
def speak(self): # method
return f"{self.name}: woof"
rex = Dog("Rex")
print(rex.speak()) # Rex: woof
The __len__ method lets you call len(obj), and any method can raise an exception when an action is impossible.