Is there any use for a top-level global variable declaration?
In Python, the global declaration is used inside function definitions to specify that assigning the variable will create/update a global variable, rather than the default local variable. Python also allows the global statement outside of function definitions. This doesn't cause an error, which leads many beginners to misuse it by writing the top-level declaration once instead of putting it in each function that needs it. It seems like this should be a syntax error, like using return outside a function or break outside a loop. Do these declarations serve any purpose, which would explain why it'
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.