When I run the following block of code in python, it seems like for input x as a integer, func3 and func4 are correctly capturing the scope of the input. However, if x is an array, func2 sees input x not as [10], but as [9]. Why? Can functions in python change variables outside the scope of that specific function? Ie, it seems like func1 is modifying the global x.
def func1(x):
x[0] -= 1
return(x)
def func2(x):
x[0] -= 2
return(x)
def func3(x):
x -= 1
return(x)
def func4(x):
x -= 2
return(x)
if __name__ == "__main__":
x = [10]
print(func1(x)) # [9]
print(func2(x)) # [7]
x = 10
print(func3(x)) # 9
print(func4(x)) # 8