b = 6 def f2(a): print(a) print(b) b = 9 UnboundLocalError: local variable 'b' referenced before assignment
- Python 编译函数的定义体时,它判断 b 是局部变量,因为在函数中给它赋值了。
b = 6 def f2(a): print(a) print(b) b = 9 UnboundLocalError: local variable 'b' referenced before assignment