id == vs is

MRAB python at mrabarnett.plus.com
Sun Oct 26 20:20:24 EDT 2014


On 2014-10-27 00:12, Dan Stromberg wrote:
> Are the following two expressions the same?
>
> x is y
>
> Id(x) == id(y)
>
> ?
>
Yes.

> I ported some Java code to Python, and it was using Java's idea of
> equality (via ==) in some places.  Right now, I have a suite of unit
> tests working using the second expression above, but I'm thinking
> about switching to the first.
>
> Thanks!
>




More information about the Python-list mailing list