• What is a closure in Python?

    Answered

    What is a closure in Python?

    Silver Member Asked on June 4, 2018 in Python.
    Add Comment
  • 1 Answer(s)
    Best answer

    A closure is said to occur when a nested function 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)()
    
    
    Silver Member Answered on June 4, 2018.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.