Classes and Objects

By the end of this lesson, you'll be able to

  • Write classes with __init__, instance attributes, and methods, and know when a class variable is the right call instead — including avoiding the mutable class variable trap
  • Write and apply decorators, and choose correctly between an instance method, @staticmethod, and @classmethod
  • Implement __str__, __repr__, and __eq__ so your own objects print and compare the way you actually want, not Python's default
  • Build class hierarchies with inheritance — super(), method overriding, and isinstance() — and recognize when inheritance is the right fit versus a closure or plain composition

Why it matters

A tool, an agent, a memory store — almost everything you’ll build later in this course ends up as a class: state that persists across calls, bundled with the operations that act on it. Tool-calling frameworks specifically lean on the OOP patterns from this lesson — @classmethod alternate constructors for building tools from config, repr for readable debug logs, inheritance for a shared Tool base class multiple concrete tools subclass from. Getting comfortable organizing state and behavior into classes now is what makes those frameworks read as familiar structure instead of unfamiliar magic.