What is a closure in Python?

Total Post:57

Points:285
 520  View(s)
Ratings:
Rate this:
  1. Post:57

    Points:285
    What is a closure in Python?

    A closure is a event in python. its occur when a nested function doing references a value in its enclosing scope.The whole point here is that it remembers the value. 

    >>> def A(x): 
        def B():
            print(x)
        return B
    >>> A(7)()

Answer