name="alex"def foo(): name="tang" #print(name) def bar(): print(name) return bar#函数名代表得就是一个函数的内存地址# a=foo()# print(a)# print(a())foo()()#由于函数bar包含在函数foo()中,所以bar会在自身查找打印的变量,如果没找到去往上一级查找,最后查找全局 #python编译器是按照顺序加载的,在调用foo()时函数bar被加载,所以必须要按照加载顺序调用函数,return返回的是函数名及函数在内存中的地址,所以可以直接使用foo()()调用# def test1():# print('in 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())