Phase 0 · Tools · Python core
Classes and objects
Bundle data with the functions that work on it.
Why it matters
Most libraries you'll use in AI work hand you objects. The Anthropic SDK gives you a client object with a messages.create method; the reply it returns is an object with .content and .usage; a NumPy array is an object with .shape and .mean(). Once you know how classes work, those dots stop being magic and become something you can read, and you can bundle your own data and logic the same way.
What you'll be able to do
- Define a class with __init__ and create objects from it
- Store data on an object as attributes and act on it with methods
- Explain what self refers to
- Read a dataclass, and judge when writing a class is worth it
Before this lesson
Next in this phase: JSON