The is
operator compares the memory addresses of two objects, and returns True
if they\'re the same. Why, then, does it not work reliably with stri
Note that this is a CPython specific optimization. If you want your code to be portable, you should avoid it. For example, in PyPy
>>>> a = "hi"
>>>> b = "hi"
>>>> a is b
False
It's also worth pointing out that a similar thing happens for small integers
>>> a = 12
>>> b = 12
>>> a is b
True
which again you should not rely on, because other implementations might not include this optimization.