Published:
You can not pass a simple primitive by reference in Python, but you can do things like: def foo(y): y[0] = y[0]**2 x = [5] foo(x) print x[0] That is a weird way to go about it, however. Note that in Python, you can also return more than one value, making some of the use cases for pass by reference less important: def foo(x, y): return x**2, y**2 a = 1 b = 2 a, b = foo(a, b) When you return values like that, they are being returned as a Tuple which is in turn unpacked. Another way to think about this is that, while you can't explicitly pass variables by reference in Python, you can modify the properties of objects that were passed in. In my example (and others) you can modify members of the list that was passed in. You would not, however, be able to reassign the passed in variable entirely. For instance, see the following two pieces of code look like they might do something similar, but end up with different results: def clear_a(x): x = [] def clear_b(x): while x: x.pop() z = [1,2,3] clear_a(z) # z will not be changed clear_b(z) # z will be emptied