The Python Language Reference, Release 3.9.5 controlled by optional arguments to$_{compile()}$ — see the documentation of that function for details. A future statement typed at an interactive interpreter prompt will take effect for the rest of the interpreter session. If an interpreter is started with the$_{-i}$option, is passed a script name to execute, and the script includes a future statement, it will be in effect in the interactive session started after the script is executed. See also: PEP 236 - Back to the __future__ The original proposal for the __future__ mechanism. $_{global_stmt}$::= "global" identifier ("," identifier )* The global statement is a declaration which holds for the entire current code block. It means that the listed identifiers are 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. Names listed in a$_{global}$ statement must not be used in the same code block textually preceding that$_{global}$ statement. Names listed in a global statement must not be defined as formal parameters or in a for loop control target, $_{class}$definition, function definition,$_{import}$ statement, or variable annotation. CPython implementation detail: The current implementation does not enforce some of these restrictions, but programs should not abuse this freedom, as future implementations may enforce them or silently change the meaning of the program. 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. nonlocal_stmt ::= "nonlocal" identifier ("," identifier )* The$_{nonlocal}$ statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope excluding globals. This is important because the default behavior for binding is to search the local namespace first. The statement allows encapsulated code to rebind variables outside of the local scope besides the global (module) scope. Names listed in a$_{nonlocal}$ statement, unlike those listed in a$_{global}$ statement, must refer to pre-existing bind- ings in an enclosing scope (the scope in which a new binding should be created cannot be determined unambiguously). Names listed in a$_{nonlocal}$ statement must not collide with pre-existing bindings in the local scope. See also: PEP 3104 - Access to Names in Outer Scopes The specification for the$_{nonlocal}$ statement. 93 7.13. The$_{nonlocal}$ statement 7.13 The nonlocal statement 7.12 The$_{global}$ statement