Pythonの名前空間

サンプルコード:

>>> a= 1
>>> def fa():
print a

>>> def fb():
print a
a = 'b’
print a

>>> def fc():
a = 'b’
print a

>>> fa()
1
>>> fb()

Traceback (most recent call last):
File ““, line 1, in
fb()
File ““, line 2, in fb
print a
UnboundLocalError: local variable 'a’ referenced before assignment
>>> fc()
b
>>> def fd():
global a
print a
a = 'b’
print a

>>> fd()
1
b
>>>

Source

Posted by arkgame