December 30, 2015
Closures and Decorators in Python
Closures basically mean that an inner function defined in an outer function remembers what its enclosing name space (or name spaces) looked like at definition time. The variables defined in this name space can later be accessed by the inner function:
def closure(): x = 1 def inner(y): return y - x return inner print(closure()(5)) 4
Closures also work, when an variable is passed to the outer function:
def otherClosure(x): def inner(y): return y - x return inner print(otherClosure(1)(5)) 4
Read more