Classes

Classes are a way to bundle functionality and state together.

A "type" and a "class" are interchangeable terms in Python: list, dict, tuple, int, str, set, and bool are all classes.

Depending on what you're doing, you might be able to get away with writing quite a bit of Python code without ever creating a class.

You'll certainly use quite a few classes in Python (remember types are classes) but you may not need to create your own often.

Classes in Python have quite a few features that are missing from some other programming languages. Python's classes use __dunder__ methods to allow for operator overloading and implementing interfaces ("protocols" as they're usually called in the Python world) such as the iterator protocol, the context manager protocol, or the descriptor protocol.

A Python Tip Every Week

Need to fill-in gaps in your Python skills? I send weekly emails designed to do just that.