I have seen people using [:]
to make a swallow copy of a list, like:
>>> a = [1,2,3,4]
>>> b = a[:]
>>> a[0] = 5
>>> print a
[5, 2, 3, 4]
>>> print b
[1, 2, 3, 4]
I understand that. However, I have seen pleople using this notation when assigning to lists as well, like:
>>> a = [1,2,3,4]
>>> b = [4,5,6,7]
>>> a[:] = b
>>> print a
[4, 5, 6, 7]
>>> print b
[4, 5, 6, 7]
But I don't really understand why they use [:]
here. Is there a difference I don't know?