Use of “global” keyword in Python

The keyword global is only useful to change or create global variables in a local context, although creating global variables is seldom considered a good solution. def bob(): me = “locally defined” # Defined only in local context print(me) bob() print(me) # Asking for a global variable The above will give you: locally defined Traceback … Read more

Are global variables bad? [closed]

The problem with global variables is that since every function has access to these, it becomes increasingly hard to figure out which functions actually read and write these variables. To understand how the application works, you pretty much have to take into account every function which modifies the global state. That can be done, but … Read more

Why are global variables evil? [closed]

This has nothing to do with Python; global variables are bad in any programming language. However, global constants are not conceptually the same as global variables; global constants are perfectly harmless. In Python the distinction between the two is purely by convention: CONSTANTS_ARE_CAPITALIZED and globals_are_not. The reason global variables are bad is that they enable … Read more