There really is a difference between a[:] = b and a = b .
>>> a = [1,2,3,4] >>> b = [4,5,6,7] >>> c = [8,9,0,1] >>> c = b >>> a[:] = b >>> b[0] = 0 >>> a [4, 5, 6, 7] >>> c [0, 5, 6, 7] >>>
When you write a = b , a is a link to the same list as b: any change to b affects
when you write a[:] = b a is a list initialized by elements b: changing b will not affect
And also the difference between a[:] = b and a = b[:] .
>>> a = [1,2,3,4] >>> b = [4,5,6,7] >>> c = a >>> a = b[:] >>> a [4, 5, 6, 7] >>> c [1, 2, 3, 4] >>> a = [1,2,3,4] >>> b = [4,5,6,7] >>> c = a >>> a[:] = b >>> a [4, 5, 6, 7] >>> c [4, 5, 6, 7]
Using a = b[:] you create a new list with elements from b, unless another variable is specified that points to a
Using a[:] = b you change the elements of a. If another variable pointed to a, it also changed.