0

When I do the is comparison on a list is acts differently than on a number or string. For example:

>>> a=[1,2,3] # id = 4344829768
>>> b=[1,2,3] # id = 4344829960
>>> a is b
False

>>> c=1 # id = 4304849280
>>> d=1
>>> c is d
True

Why is this so?

  • If you had done `id(d)`, you would have answered your question – smac89 Oct 20 '19 at 02:31
  • @smac89 -- right, why doesn't the list have the same memory address if the elements are all the same? –  Oct 20 '19 at 02:54
  • The content of the list does not define its memory address. I think you may be confusing memory address with hash value of an object. The two lists may store the same values, but they are different lists because you created them separately. If you did `b = a`, then you would have got `true`. – smac89 Oct 20 '19 at 03:00

0 Answers0