Inside a function, assigning to a name normally creates or updates a local variable. Add `global name` when retrievals and assignments must use the module-level variable instead. section 7.5
x = 100
def foo():
x = 200
print(x)
print(x)
foo()
print(x)
Compare a local `x` with the module-level `x`; the function's assignment leaves the outer value unchanged. section 7.5
x = 100
def foo():
global x
x = 200
print(x)
print(x)
foo()
print(x)
The `global x` declaration makes the function update the single module-level `x`, so the later print sees `200`. section 7.5
Use this sparingly: changing global state is almost always a poor choice, though updating a global configuration parameter can be necessary. Mutating an existing global list item or dictionary value does not require `global`. section 7.5


