Function Fundamentals
By the end of this lesson, you'll be able to
- Write functions with type hints and docstrings that later tool-calling frameworks can generate schemas and descriptions from
- Use *args/**kwargs to build wrappers that forward calls without needing to know a function's exact signature
- Reason correctly about local, global, and closure scope — including the mutable default argument trap — and know when a closure is a lighter alternative to a class
- Use lambda, map, filter, and sorted(..., key=...) where they genuinely fit, and comprehensions where idiomatic Python actually prefers them
- Split code across multiple files with imports, and control what runs on direct execution vs. import with if __name__ == "__main__":
Why it matters
Agent code is built almost entirely out of functions being passed around, wrapped, and forwarded — a tool is a function, a callback is a function, a factory that configures a tool is a closure returning a function. Getting comfortable with how Python passes, scopes, and organizes functions across files is what makes the framework-specific code later in this course readable instead of mysterious.