The official Python tutorial (2.7) says that a slice makes a shallow copy of a list (e.g.), and each element in the slice is a reference to the original list object.
For example, performing
a = [1,2,3] a[:][0] = 2
will not change the actual value, because only the first element in the slice refers to a new object (which is 2).
However, making
a[:] = [] # or any other list
really change the list.
Can someone explain this?
python
pspencil
source share