0

I known that 'is' in Python is compare two object's id. But why the same compare will return different result?

Here is a example code for my question. (Python 2 and 3 as same)

>>> x = '123'
>>> y = '123'
>>> x is y
True
>>> x *= 100
>>> y *= 100
>>> x is y
False
Jack
  • 58
  • 1
  • 9
  • Fun fact: if Python 3, `import sys.intern as intern`, then `intern(x) is intern(y)` gives `True`; basically you force Python to eliminate duplicates. See [this other dup](https://stackoverflow.com/q/15541404/1270789) for more details. – Ken Y-N Nov 16 '17 at 08:33
  • 1
    @KenY-N The marked dupe is the wrong one, the question is about strings not integers; your linked one is better – Chris_Rands Nov 16 '17 at 08:38
  • 1
    @Chris_Rands indeed; there were three distinct dups flagged, including the one I linked to in the comment above, but for some reason only one is showing. – Ken Y-N Nov 16 '17 at 08:40

0 Answers0