DEV Community

michael miller
michael miller

Posted on

Closure

In Python, a closure is a function object that remembers values in enclosing scopes even if they are not present in memory. It is a record that stores a function together with an environment: a mapping associating each free variable of the function (variables that are used locally, but defined in an enclosing scope) with the value or reference to which the name was bound when the closure was created. Closures are used to avoid the use of global variables and provides some form of data hiding, as it encapsulates the function with its environment.

Top comments (0)