In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the function’s body(即便没用到), it’s assumed to be a local unless explicitly declared as global.
https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python
>>> from math import pi
>>> pi
3.141592653589793
>>> def s():
if pi:
print('if pi')
else:
print('in else')
>>> s()
if pi
>>> def s():
if pi:
print('if pi')
pi=3
elif pi<3:
print('elif pi<3')
>>> s()
Traceback (most recent call last):
File "", line 1, in
s()
File "", line 2, in s
if pi:
UnboundLocalError: local variable 'pi' referenced before assignment