May-12-2023, 04:40 AM
Just learning about using a global variable. I have this going:
I don't quite get it. If I declare a global variable that can be seen and accessed in the show_value function, then why can't I modify it in the function as well?
x = 4 def show_value(): print('Value of x: '+ str(x)) # x += 3 # print('Value of x: '+ str(x)) show_value()I had to comment out those two lines in order to get the program to run. I thought that in my show_value function I could modify the value of the variable, but apparently I cannot because the compiler flagged it.
I don't quite get it. If I declare a global variable that can be seen and accessed in the show_value function, then why can't I modify it in the function as well?