Classes are a way to bundle functionality and state together.
A "type" and a "class" are interchangeable terms in Python:
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 every 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.
Hello friendly web visitor! 👋
This page is part of Python Morsels, an online Python skill-building service.
The best way to learn is by doing. In the case of Python that means writing Python code. If you'd like to improve your Python skills every week, try out Python Morsels by entering your email below to create an account.
Python Morsels topics pages are free and the first month's worth of exercises is free as well. You don't need to enter payment details to sign up.
You can find explanations of many other Python topics by signing up below.