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. Bothaandbrefer to the same objectid(a)==id(b)does whata is bdoes.Now, Incase1
(a is b) == ( id(a) == id(b) )this isTrue==Truewhich returnsTrue. In second case(a is b) == ( id(a) == id(b) )this isFalse==Falsewhich returnsTrueFrom Docs: