What I assume you want to achieve is to pass your arguments by reference, so that they get changed by the function.
You cannot achieve that passing immutable arguments (like numbers) into your function. To deal with that, take a look at the official docs. For clarity I'd strongly advise to use solution 1, though it uses a return
statement:
def m(x,y):
x = 2
y = [3,5]
return x,y
a = 1
b = [0,26]
a,b = m(a,b)
print a,b
Achieving this "without return
" is possible using one of the other solutions given in the documentation. From those I'd say solution 3 is preferable, though it's much less clear and straightforward than solution 1. You pass a mutable argument to your function, like a list
:
def m(x):
x[0] = 2
x[1] = [3,5]
a = [1, [0,26]]
m(a)
print a