函数的作用域只跟函数声明时定义的作用域有关,跟函数的调用位置无任何关系
def test1(): print('in the test1') def test(): print('in the test') return test1 print(test) res=test() print(res()) #test1()
输出
<function test at 0x0000000002995620> in the test in the test1 None
name = 'alex' def foo(): name='linhaifeng' def bar(): name='wupeiqi' print(name) return bar a=foo() print(a) a() #bar()
输出
<function foo.<locals>.bar at 0x0000000002995620>
wupeiqi