Using id
you can see that they refer to the same object.:
>>> l = [[]]*5
>>> for i in l:
print id(i)
42277424
42277424
42277424
42277424
42277424
>>>
>>> l[0].append(1)
>>> l
[[1], [1], [1], [1], [1]]
>>> id(1)
32851648
>>> for lst in l:
for item in lst:
print 'item : {0}, list : {1}'.format(id(item), id(lst))
item : 32851648, list : 42277424
item : 32851648, list : 42277424
item : 32851648, list : 42277424
item : 32851648, list : 42277424
item : 32851648, list : 42277424
As you can see, l
actually have five same references to one object, []
. So if you change anyone of them, you will see the same effect on the rest items