-2

I know that copying list with the following code will perform a shallow copy. i.e New list is created.

>>> L = [1,2,3,4,5]
>>> L_copy = L[:]
>>> L_copy

>>>[1, 2, 3, 4, 5]

>>> L_copy is L

False

How is the following code executed:

L[:] = some_list

I saw it in one example.

This is my first question on stackoverflow.

1 Answers1

0

L[:] created an object that is equal to but it's not the same object.

>>> L = [1,2,3,4,5]
>>> _L = L[:]
>>> print L,_L
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
>>> L == _L
True
>>> L is _L
False
>>>

All, that is tells you is that L and _L are not the same object.

>>> L[:] == L[:]
True
>>> L[:] is L[:]
False
>>>
shrewmouse
  • 5,338
  • 3
  • 38
  • 43