Question #691

What is a closure?

A closure, unlike a plain function, allows a function to access variables captured through the closure’s copies of their values or references, even when the function is invoked outside their scope. Looking at the code below:

def outerFunction(text): 
    text = text 
  
    def innerFunction(): 
        print(text) 
  
    return innerFunction
  

myFunction = outerFunction('hello') 
myFunction() 

will return:
>>hello"

(geeksforgeeks.org/python-closures)


Comment on Disqus:

Comment on Twitter:

Question difficulty: 🔵🔵🔵🔵🔵