1, the definition of closures:
When a child function has a call to a parent function variable (not a global variable) and returns a child function name, the parent function does not end the release as the function runs, but instead saves the state waiting for the call of the child function.
Our common types of closures:
def fun1 (): = 1 def fun2 (): return x return fun2
g = fun1 ()
Print (g ())
Such closures are sure to be visible at a glance.
So, what about this:
#1
deffun1 (): Lis=[] Name='Alex' deffun2 ():Print(name) lis.append (fun2)returnLISG=fun1 () g[0] () #2lis= []deffun1 (): Name='Alex' deffun2 ():Print(name) lis.append (fun2) G=fun1 () lis[0] ()
Run the above program you will find that it is actually closures, the first fun2 called the parent function's name variable, and then the function name is returned by putting it in the list. In the second, the function name is returned through a mutable list of global variables, so it is also a closure function.
Python----Special closures