The keyword "global" has a special purpose . If you look into the help docstring of this keyword, you must notice this line :
Now . In python , if you declare a variable outside the scope of all functions or classes, it is AVAILABLE GLOBALLY. Meaning I can use it anywhere anytime.
But what is NOT clear , is , you CANNOT change the value\contents of this variable.
Bringing statefulness into your program (e.x an integrating counter ), might need you to keep updating some variable's value . That means, functions must be able to change that value.
Hence, the keyword "global" .
It would be impossible to assign to a global variable without "global "
The word to note is "Assign"
But what is NOT clear , is , you CANNOT change the value\contents of this variable.
Bringing statefulness into your program (e.x an integrating counter ), might need you to keep updating some variable's value . That means, functions must be able to change that value.
Hence, the keyword "global" .