In python, is a function return a shallow or deep copy?
In python everything is a reference. Nothing gets copied unless you explicitly copy it.
In your example, x
and y
reference the same object.
It will be a shallow copy, as nothing has been explicitly copied.
def foo(list):
list[1] = 5
return list
For example:
>>> listOne = [1, 2]
>>> listTwo = [3, 4]
>>> listTwo = listOne
>>> foo(listTwo)
[1, 5]
>>> listOne
[1, 5]