Skip to content

Functions

Functions are where Python programs stop being lists of instructions and start being compositions of ideas. This guide takes you from defining your first function, through the idiomatic features Python adds on top (default arguments, type hints, docstrings, *args/**kwargs, decorators), to the concepts that explain why functions in Python behave the way they do.

Start here

If functions are new to you, work through the Learn section in order — seven short notebooks, around fifteen minutes each. You can run them directly in the Lab without installing anything.

If you already know the basics and have come looking for a specific technique, jump to the Recipes section or scan the Reference.

What this guide covers

Learn — defining functions, lambdas, type hints, docstrings, scope and closures, *args/**kwargs, decorators.

Recipes — default and keyword arguments, recursion, writing decorators, higher-order functions, argument validation.

Reference — function syntax, built-in functions, type hint syntax, docstring conventions.

Concepts — why functions matter, first-class functions, scope and namespaces, the Zen of functions.