# nested functions
def outerFunction(text):
def innerFunction():
2.A closure—unlike a plain function—allows the function to access those captured variables through the closure’s copies of their values or references, even when the function is invoked outside their scope.
# closures
def outerFunction(text):
def innerFunction():
myFunction()
2.The function innerFunction has its scope only inside the outerFunction. But with the use of closures we can easily extend its scope to invoke a function outside its scope
# closures
import logging
logging.basicConfig(filename='example.log', level=logging.INFO)
def logger(func):
return log_func
sub_logger = logger(sub)
add_logger(3, 3)
add_logger(4, 5)
sub_logger(10, 5)
sub_logger(20, 10)
9
5
10