Identity operator vs. Comparison operator

by kiawin

A kind python reminder :)

In some cases, comparing the identity of two strings or numbers—for example,
using a is b—will return True, even if each has been assigned separately as we
did here. This is because some implementations of Python will reuse the same
object (since the value is the same and is immutable) for the sake of efficiency.
The moral of this is to use == and != when comparing values, and to use is and
is not only when comparing with None or when we really do want to see if two
object references, rather than their values, are the same.

Quoted from Programming in Python 3 (2nd Edition) by Mark Summerfield.