You can use a global variable in other functions by declaring it as global in each function that assigns to it.
I imagine the reason for it is that, since global variables are so dangerous, Python wants to make sure that you really know that’s what you’re playing with by explicitly requiring the
globvar = 0
# Needed to modify global copy of globvar
globvar = 1
# No need for global declaration to read value of globvar
# Prints the output
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.