@@ -139,8 +139,9 @@ namespace. Names are resolved in the top-level namespace by searching the
139
139
global namespace, i.e. the namespace of the module containing the code block,
140
140
and the builtins namespace, the namespace of the module :mod: `builtins `. The
141
141
global namespace is searched first. If the names are not found there, the
142
- builtins namespace is searched. The :keyword: `!global ` statement must precede
143
- all uses of the listed names.
142
+ builtins namespace is searched. If the name is also not in the builtins namespace,
143
+ a new variable is created in the global namespace. The :keyword: `!global ` statement
144
+ must precede all uses of the listed names.
144
145
145
146
The :keyword: `global ` statement has the same scope as a name binding operation
146
147
in the same block. If the nearest enclosing scope for a free variable contains
@@ -151,7 +152,8 @@ a global statement, the free variable is treated as a global.
151
152
The :keyword: `nonlocal ` statement causes corresponding names to refer
152
153
to previously bound variables in the nearest enclosing function scope.
153
154
:exc: `SyntaxError ` is raised at compile time if the given name does not
154
- exist in any enclosing function scope. :ref: `Type parameters <type-params >`
155
+ exist in any enclosing function scope, or if the nearest enclosing scope is
156
+ the global (module) scope. :ref: `Type parameters <type-params >`
155
157
cannot be rebound with the :keyword: `!nonlocal ` statement.
156
158
157
159
.. index :: pair: module; __main__
0 commit comments