Variables that are defined outside of functions (in the global area) are called global
variables. When you use a global variable inside a function, you are actually creating a local variable that is different from the global one. To change a global variable from inside a function, you should say that you want to refer to the global variable.
def change():
global string, num1, num2
string = 'gone'
num1 = 0
num2 = 0
Now if you call change
, they will change globally.
However this is not a good approach, it's better that you keep functions as a black box that don't have any side effect; So it's better that you do it this way:
def change():
s = 'gone'
n1 = 0
n2 = 0
return s, n1, n2
string, num1, num2 = change()