decorator pattern print("inside fib"if return fibprev fib for num in range( )fibprevfib fibfib fibprev return fib if __name__ ="__main__" print("fibonacci number for {}{}format(nfib( ))get ready for bit of mind bender the decorator function must return function to be used when the decorated function is called the returned function is used to wrap the decorated function the wrapped_f(function is created when the function is calledso it has access to all the arguments passed to the profiling_decorator(function this technique by which some data (in this casethe function passed to the profiling_ decorator(functiongets attached to code is called closure in python closures let' look at the wrapped_f(function that accesses the non-local variable that is passed in to the profiling_decorator(function as parameter when the wrapped_f(function is createdthe value of the non-local variable is stored and returned as part of the functioneven though the original variable moves out of scope and is removed from the namespace once the program exits the profiling_decorator(function in shortto have closureyou have to have one function returning another function nested within itselfwith the nested function referring to variable within the scope of the enclosing function