[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Odd truth result with in and ==

On 21Nov2018 19:40, MRAB <python at mrabarnett.plus.com> wrote:
>On 2018-11-21 19:18, Python wrote:
>>>>>1 in [1,2,3] == True
>It's a chained comparison. It applies to '<', '<=', '>', '>=', '==' 
>and '!=', but also to 'in', although I've never seen a chained 
>comparison using 'in' in practice.

Me either. In fact, I was as stumped as the OP. I've never really 
considered "in" as a comparison; in my mind comparisons are between like 
items: numbers vs numbers, and so forth. Not elements versus a 
collection of elements.

Can someone show me a real world, or failing that - sane looking, 
chained comparison using "in"?

Cameron Simpson <cs at cskk.id.au>