What are the semantics of the ‘is’ operator in Python?

From the documentation:

Every object has an identity, a type
and a value. An object’s identity
never changes once it has been
created; you may think of it as the
object’s address in memory. The ‘is‘
operator compares the identity of two
objects; the id() function returns an
integer representing its identity
(currently implemented as its
address).

This would seem to indicate that it compares the memory addresses of the arguments, though the fact that it says “you may think of it as the object’s address in memory” might indicate that the particular implementation is not guranteed; only the semantics are.

Leave a Comment