Game of Greed 2

Python Scope & the LEGB Rule

Modifying the Behavior of a Python Scope

Python provides the keywords (global and nonlocal) as to change the content of global and nonlocal names, however it is a bad practice.

The global Statement

… global_counter = 0 # A global name … def update_counter(counter): … return counter + 1 # Rely on a local name

The nonlocal Statement