Apr-05-2018, 02:43 AM
Therein lies the evil of global variables.
The answer to your question is yes and yes.
Consider the following,
The program will eventually fail precisely because you are allowed to change a global variable anywhere
The answer to your question is yes and yes.
Consider the following,
The program will eventually fail precisely because you are allowed to change a global variable anywhere
MyGlobal = 17 def function_1(n): MyGlobal += n def function_2(): global MyGlobal print('MyGlobal is {}'.format(MyGlobal)) def function_3(): global MyGlobal MyGlobal = str(MyGlobal) def function_4(): global MyGlobal for n in range(5): MyGlobal += n function_2() def main(): function_4() function_3() function_4() if __name__ == '__main__': main()