Python3> Functions> Symbol table> Assign to variables / Reference variables / Global variables / globals () / locals ()

Python 3.5.2 documents

http://docs.python.jp/3/tutorial/controlflow.html#defining-functions

4.6. Define a function ... When you execute a function, you will have a new symbol table </ font> that will be used for the function's local variables. More precisely, when you make a variable assignment </ font> inside a function, all its values are stored in this local symbol table. On the other hand, doing a variable reference </ font> first looks up the local symbol table, then the local symbol table of the outer function, and then ...

Therefore, you can refer to a global variable in a function, but you cannot directly assign a value (unless you name it in the global statement).

It is unclear whether Python 3 can be used well by being aware of the symbol table.


(Added on 2016/11/01)

@shiracamus told us about globals () and locals () in the comments.

Thank you for the information.