You cannot do this. Others explained this already:
- Python: How do I pass a variable by reference?
- How do I write a function with output parameters (call by reference)?
However from a design standpoint, you have at least two alternatives:
-
Use return values:
def incdec(x, y, d): return x + 1, y - 1 x, y = incdec(x, y, d)
-
Use a mutable type:
def incdec(payload, d): payload['x'] += d payload['y'] -= d payload = {'x': 10, 'y': 4} incdec(payload) print(payload) # prints {'y': 3, 'x': 11}