I am trying to change global value x
from within another functions scope as the following code shows,
x = 1
def add_one(x):
x += 1
then I execute the sequence of statements on Python's interactive terminal as follows.
>>> x
1
>>> x += 1
>>> x
2
>>> add_one(x)
>>> x
2
Why is x
still 2 and not 3?
x
is a local, not a global. – Horrendous