func_two
def func_two(x):
x[1][1] = x[2][1]
x[2][1] = 0
return x
a = [[12, 11, 7, 13], [6, 0, 8, 3], [9, 4, 10, 2], [5, 14, 15, 1]]
print(a, ":before function")
b = func_two(a)
print(a, ":after function")
print(b, ":value of b")
output for this is
[[12, 11, 7, 13], [6, 0, 8, 3], [9, 4, 10, 2], [5, 14, 15, 1]] :before function
[[12, 11, 7, 13], [6, 4, 8, 3], [9, 0, 10, 2], [5, 14, 15, 1]] :after function
[[12, 11, 7, 13], [6, 4, 8, 3], [9, 0, 10, 2], [5, 14, 15, 1]] :value of b
why did the value of "a" change after the function? how do I run the func_two without changing the variable outside the function (I haven't declared any variable as a global variable, this shouldn't happen)
code that works correctly func_one
def func_one(x):
x = [[3]]
return x
a = [[5]]
print(a, ":before function")
b = func_one(a)
print(a, ":after function")
print(b, ":value of b")
output for this is
[[5]] :before function
[[5]] :after function
[[3]] :value of b
why is func_one working when func_two is not working ?