1

When I do

a = "myString"
b = "myString"

a is b
> True

and this is true if the strings are identical, no matter the length. however, when I add a whitespace in there, the identity is no longer the same. so

a = "my string"
b = "my string"

a is b
> False

Why is this happening? how is the whitespace affecting the string in such a way that the identities are no longer the same?

is this an issue only in python 2.7?

Arturo
  • 171
  • 1
  • 17
  • You should **never rely on string identity** when checking for string equality. The rules for string interning and constant folding in code blocks are arcane and vary between different versions. In this case **you should not expect the identities to be the same**, it is a happy optimization that the compiler does for us, but which you shouldn't rely on. – juanpa.arrivillaga Mar 27 '19 at 17:39

0 Answers0