Using global variables in a function

Posted by Rohit Kumar | Updated on

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¬†global¬†keyword.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers