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?
 
                        
Because
xis a local (all function arguments are), not a global, and integers are not mutable.So
x += 1is the same asx = x + 1, producing a new integer object, andxis rebound to that.You can mark
xa global in the function:There is no point in passing in
xas an argument here.