In Python, the expression (a is b) == ( id(a) == id(b) )
appears to always returns True, where a
and b
are variables referring to some object, since the id
function returns the memory where they are stored and is
is used for object identity.
Are there any exceptions?
This expression is always
True
. There are two possible ways: 1. Botha
andb
refer to the same objectid(a)==id(b)
does whata is b
does.Now, Incase1
(a is b) == ( id(a) == id(b) )
this isTrue==True
which returnsTrue
. In second case(a is b) == ( id(a) == id(b) )
this isFalse==False
which returnsTrue
From Docs: