Overview - Global keyword
What is it?
The global keyword in Python is used inside a function to tell the program that a variable refers to the one defined outside the function, at the global level. Without this keyword, Python treats variables assigned inside a function as local to that function. This keyword helps you change or use global variables from within functions.
Why it matters
Without the global keyword, you cannot modify global variables inside functions, which limits how functions interact with the rest of the program. This would make it harder to share and update data across different parts of your code, leading to more complex and less readable programs.
Where it fits
Before learning the global keyword, you should understand variables, functions, and variable scope (local vs global). After this, you can learn about nonlocal keyword, closures, and best practices for managing state in larger programs.