0

I understand that Python mutables like lists have different identities while "special situations" like certain strings and numbers will have the same IDs but I don't understand this situation:

>> a = [[0]*2]*2
>>> a
[[0, 0], [0, 0]]
>>> id(a[0])
140387455550664
>>> id(a[1])
140387455550664

Both [0,0] lists in the list a have the same ID

However, when I create a list like this, the IDs are different for each list element in that list

>>> b = [[0,0],[0,0]]
>>> id(b[0])
140387455550472
>>> id(b[1])
140387456353480

I am using CPython/Python 3.6 on Ubuntu

sami
  • 723
  • 2
  • 9
  • 23

0 Answers0