Multiple comparisons in a single statement

Chris Angelico rosuav at gmail.com
Fri Mar 13 07:13:52 EDT 2020


On Fri, Mar 13, 2020 at 8:36 PM Stephen Tucker <stephen_tucker at sil.org> wrote:
>
> *Chris:*   Thank you for your confirmation.
>
> *All:  *For the record, I meant that the tuples are all the same. The
> tuples I have in mind contain strings, so the issue regarding the
> "equality" (or otherwise) of 0 and 0.0 does not arise in my case.
>
> Stephen.

If you create the tuples independently, they can be equal but not
identical. Example:

>>> def cons(x, y): return x, y
...
>>> spam = cons("foo", "bar")
>>> spon = cons("foo", "bar")
>>> spam == spon
True
>>> spam is spon
False

For the most part, you won't care about identity, only equality.
Everything you said was correct for equality.

ChrisA


More information about the Python-list mailing list