Assignment in Python does not change the object in place. It restores the name so that after input = new_val local variable input receives a new value.
If you want to change the "external" input , you have to wrap it inside a mutable object, such as a list of one element:
def foo(input, new_val): input[0] = new_val foo([input])
Python does not pass by reference in the same way that a C ++ link works. In this case, at least it's more, as if each argument was a pointer in C / C ++:
source share