def foo(x, j, k): """ x is a list, j, k indices of the list""" if j != k: x[j], x[k] = x[k], x[j] x = [1,2,3] print(x) foo(x, 0, 1) print(x)