python basis - function scope

name = " alex " 
DEF foo (): 
    name = " Tang " 
    # Print (name) 
    DEF bar (): 

        Print (name)
     return bar # function delegates have is a function of memory address 
# A = foo () 
# Print (a) 
# Print (a ()) 
foo () () # Since the function bar is included in the function foo (), the bar looks so variable print on its own, if not found up to find one, look for the global final 
#python compiler is loaded in the order, the function bar is loaded when calling foo (), it is necessary to call a function in accordance with the loading sequence, return is a function name and return address of a function in memory, you can use directly foo ( ) () call
# DEF test1 (): # Print ( 'in at The test1') # return 1 # # def test(): # print("in the test") # return test1() # # #print(test) # a=test() # print(a) # def test1(): # print('in the test1') # #return 1 # # def test(): # print("in the test") # return test1 # # #print(test) # res=test() # print(res())

 

Guess you like

Origin www.cnblogs.com/tangcode/p/10984094.html