Keywords and Control Flow
global — Module namespace binding
Declare that listed names refer to the current module’s global namespace throughout the enclosing code block. Reading an existing global normally needs no declaration; rebinding it inside a function does. Mutating an object through an existing name is different from rebinding that name. The declaration is a compile-time directive and does not create an object or import a value. Use or assignment before the declaration in the same scope is invalid in ordinary script code.
Formal Syntax & Structure
python syntaxpython
global name[, another_name ...]Working Example
Example Snippetpython
count = 0
def increment(): global count count += 1
increment()increment()print(count)