Odd truth result with in and ==

Ian Kelly ian.g.kelly at gmail.com
Wed Nov 21 18:45:32 EST 2018


On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka <storchaka at gmail.com> wrote:
>
> 21.11.18 22:17, Cameron Simpson пише:
> > Can someone show me a real world, or failing that - sane looking,
> > chained comparison using "in"?
>
>      s[0] == s[-1] in '\'"'
>
> Tests that string s starts and ends with a single or double quote.

Clever, but too esoteric to use in practice. I'd rather make the
chaining explicit.

> It can be also used with sets:
>
>      elem in set1 <= set2

I like this one better.



More information about the Python-list mailing list