Skip to main content
Loading page…
Python Mastery
Chapter 17
Lesson 1 of 3
Closures & First-Class Functions
Contents
Notes
Tutor
Note
Coming from the Functional Python Module
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
25 min
8 activities
0 of 8 done
In this lesson
1
Coming from the Functional Python Module
2
What Is a Closure?
3
Building a Counter Factory
4
The nonlocal Gotcha
5
Check: What Does nonlocal Do?
6
Practical Uses of Closures
7
Practice: Build a Rate Limiter Closure
8
Pro Tip: Closures vs Classes
Objectives
Pass functions as arguments and return them from other functions
Build a closure that captures and retains state across calls
Use nonlocal to mutate a captured variable inside a nested function
Implement a counter factory using closures
Chapter 17 · Decorators, Closures & Context Managers
Closures & First-Class Functions
Decorators
Context Managers (with)
Previous: itertools, map, filter
Next: Decorators