I am having this issue in a large code base so I created a small reproducer below:
Here, I have the following two functions, func2() and func3()
def func2(a,b):
a = 'new-value'
b = b+1
return a, b
def func4():
x,y = 'old-value',3
func2(x,y)
print(x,y)
The output I am getting is:
>>> func4()
old-value 3
I thought Python is pass-by assignment and so the func4()
should overwrite x
and y
values by new-value
and 4
What am I misunderstanding? Also, how can I change the above code to make x
, y
have new-value
and 4
Any help is greatly appreciated!.