Python โ From Basics to Advanced ยท Advanced Functions
Closure โ Functions That Remember Context
Advanced Functions
Introduction
A function nested inside another function can access the outer function variables โ even after it has returned. That is a closure. It is the foundation of decorators and many functional patterns. In this lesson you understand the mechanism and avoid common pitfalls.