Recipes: Python Functions¶
Short, task-focused how-tos for specific things you'll want to do with functions. Each recipe assumes you already know the basics — if a term surprises you, the Learn section is one click away.
Unlike the tutorials, the recipes don't have a recommended order. Pick whichever is useful right now.
Recipes in this guide¶
- Use default and keyword arguments effectively — practical patterns for flexible function signatures.
- Write recursive functions — the shape of a good recursive function and the pitfalls to avoid.
- Create decorators — writing your own decorators that wrap other functions.
- Work with higher-order functions —
map,filter, function composition, and when to reach for each. - Validate function arguments — catching bad inputs early and giving clear errors.