How can I create a function that updates the value of one of its arguments? Consider the following example:
def f(x,b):
b+=1
return x*b
b=4
a=f(1,b)
print a
print b
The update of b
is valid only inside the function, but b
keeps its original value after the function has been used. Of course, in this case I could just solve the problem by returning also b
and then using a,b=f(1,b)
but I do not want to do it.
What should I do if I actually want b
to be updated and change its value without returning it explicitly ?