The global statement causes the listed identifiers to be interpreted as globals. It would be impossible to assign to a global variable without global, although free variables may refer to globals without being declared global.
The global statement applies to the entire current scope (module, function body or class definition). A SyntaxError is raised if a variable is used or assigned to prior to its global declaration in the scope.
At the module level, all variables are global, so a global statement has no effect. However, variables must still not be used or assigned to prior to their global declaration. This requirement is relaxed in the interactive prompt (REPL).
Programmer’s note:global is a directive to the parser. It applies only to code parsed at the same time as the global statement. In particular, a global statement contained in a string or code object supplied to the built-in exec() function does not affect the code block containing the function call, and code contained in such a string is unaffected by global statements in the code containing the function call. The same applies to the eval() and compile() functions.