PyPython · Lesson 9 of 14
Classes & OOP
Python classes are simpler than Java or C++ — no access modifiers, no header files, and you can add attributes whenever you want. This is either liberating or terrifying, depending on your background.
A class is a blueprint for creating objects. Python uses the __init__ method as the constructor. The self parameter is the instance — Python passes it automatically, but you must declare it explicitly in every method.
◆ Note
Use dataclasses for plain data containers. Use regular classes when you need complex initialization, inheritance, or custom descriptors. The @dataclass decorator auto-generates __init__, __repr__, and __eq__ based on your field annotations.
Use dataclasses for plain data containers. Use regular classes when you need complex initialization, inheritance, or custom descriptors. The @dataclass decorator auto-generates __init__, __repr__, and __eq__ based on your field annotations.