logo

String Interning

Last Updated: 2022-04-04

Strings will be interned, saved as one object, so is is returning True

>>> S1 = 'spam'
>>> S2 = 'spam'
>>> S1 == S2, S1 is S2
(True, True)

Another example

>>> S1 = 'alonglongstring'
>>> S2 = 'alonglongstring'
>>> S1 == S2, S1 is S2
(True, True)

String with empty space, is is returning False

>>> S1 = 'a longer string'
>>> S2 = 'a longer string'
>>> S1 == S2, S1 is S2
(True, False)