Go beyond the basics of functions to master recursion and the call stack, the LEGB scope rules with global and nonlocal, lambdas and closures, and the functional trio of map, filter and reduce. Sharpen the higher-order-function fluency the Python Institute PCAP certification rewards, and learn when a comprehension beats a functional pipeline.
Watch the free preview
Recursion — base case and recursive case — free to watch, no account needed.
What you'll learn
- Write correct recursive functions with a base case and a shrinking recursive case
- Explain how the call stack drives recursion and why Python limits recursion depth
- Resolve variable names using the LEGB rule and control scope with global and nonlocal
- Use lambdas, higher-order functions and map, filter and reduce to transform data
- Build closures that capture private state and choose between comprehensions and functional style
Syllabus
Recursion & the Call Stack
Recursion — base case and recursive caseFree preview
The call stack and recursion limits
Scope — LEGB, global & nonlocal
Scope and the LEGB rule
The global and nonlocal keywords
Lambdas & Functional Tools
Lambdas and higher-order functions
map, filter and reduce
Closures & Functional Style
Closures — functions that remember
Comprehensions versus functional style
Lab — 10 Programming Exercises & Solutions
Programming Exercises 1–5
Programming Exercises 6–10