Journey to JSR223 Python 7 of 9

It’s a Python thing. Variables from a parent scope are read only. If you set them in the local scope you create a local variable with the same name.

def plus_one():
    one += 1
    print("plus one: " + one)

def plus_two():
    global one
    one += 2
    print("plus two: " + one)

one = 1
print("one: " + one)
plus_one()
print("two: " + one)
plus_two()
print("three: " + one)

Results in:

one: 1
plus one: 2
two: 1
plus two: 3
three: 3