I would like to ask you for help about the behaviour of a slicing operator in Python.
- On the one hand we know that
L[:]
creates a shallow copy of the listL
. To verify it one can just printid(L), id(L[:])
and notice that they are different. - On the other hand we know that
del L[:]
removes references from the original object. It makes the original list empty - not the shallow copy of it. Of course I agree that creating a shallow copy, then removing references from it, would make little sense so I understand that here we want to operate on the original list.
Is there any rule saying when slicing operator creates a shallow copy and when it doesn't? How can I know it without manually testing it?
I searched for this and found these topics:
but unfortunately they do not answer my question, at least I do not see it.