When defining a function, the Python language allows its function to include the complete definition of another function. This is what we usually call nested definition.
Instance 1:
Def OutFun (): # define the function OutFun (), m = 3 # define the variable m = 3; def InFun (): # define the function InFun () in OutFun () n = 4 # define the local variable n = 4 print m + n # m is equivalent to the global variable InFun () of the function InFun () # Call the function InFun () in the OutFun () function ()
Instance 2:
Def InFun (m): n = 4 print m + ndef OutFun () m = 4 InFun (m)
Instance 2 first defines the function InFun (), and then defines the OutFun () function again. At this time, the InFun () and OutFun () functions are completely independent, and OutFun () inFun () is called in the function. In fact, the nesting function in instance 1 and instance 2 has the same effect, but there are two different manifestations.