id == vs is
Ben Finney
ben+python at benfinney.id.au
Sun Oct 26 20:40:24 EDT 2014
Dan Stromberg <drsalists at gmail.com> writes:
> Are the following two expressions the same?
>
> x is y
>
> Id(x) == id(y)
It depends what you mean by “the same”.
Do they give the same result? Sometimes yes, sometimes no. It depends on
what the types of the values are.
Do they express the same intent? Always no. The first queries object
identity, the second queries object equality.
--
\ “Ridicule is the only weapon which can be used against |
`\ unintelligible propositions.” —Thomas Jefferson, 1816-07-30 |
_o__) |
Ben Finney
More information about the Python-list
mailing list