一:函数调用顺序:其他高级语言类似,Python 不允许在函数未声明之前,对其进行引用或者调用错误示范: def foo(): print 'in the foo' bar() foo() 报错: in the foo Traceback (most recent call last): File "<pyshell#13>", line 1, in <module> foo() File "<pyshell#12>", line
情况一: a 直接引用外部的,正常运行 def toplevel(): a = 5 def nested(): print(a + 2) # theres no local variable a so it prints the nonlocal one nested() return a 情况二:创建local 变量a,直接打印,正常运行 def toplevel(): a = 5 def nested(): a = 7 # create a local variable called a w