Hmm... An idea: if a,b==c,d:

Alex Martelli aleax at aleax.it
Mon Nov 18 18:45:55 EST 2002


Richard Dillingham wrote:

>> It's better written as:
>>
>> if coords[0]<=posx<=coords[2] and coords[1]<=posy<=coords[3]:
> 
> Hmm.... I just tried that, and am quite amazed to find that it actually
> works.

Python comparison operators CHAIN -- a wonderful little trait...

I'd never use it confusingly with e.g. x > y <= z (it would work for
that, too, but I think it's unreadable...) -- but with comparisons
going uniformly left-right, it's quite readable IMHO.


Alex




More information about the Python-list mailing list