Two individually created mutable list have different ids.
Python SHELL: (mutable)
>>> mylist = ['spam', 'eggs']
>>> yourlist = ['spam', 'eggs']
>>> id(mylist), id(yourlist)
(49624456, 48910408)
While two individually created immutable strings have similar ids.
Python SHELL: (immutable)
>>> a = 10
>>> b = 10
>>> id(a), id(b)
(507099072, 507099072)
Is a
and b
referencing to a same object? If no, why ids are similar?
Is mylist
and yourlist
referencing to different objects? If yes, why they have different ids.