0

Can anyone tell me why following code gives different answers?

>>> a='3x'
>>> b='3x'
>>> a is b
True

>>> a='3[x'
>>> b='3[x'
>>> a is b
False

--- EDIT ---

Thanks for the comment from Jean, so their ids are different because the strings are not cached, that make sense.

The thing that interested me is, when I try this in the PythonTutor website it returns True.

martineau
  • 112,593
  • 23
  • 157
  • 280
Deqing
  • 12,998
  • 13
  • 78
  • 120

0 Answers0