[Python-ideas] PEP 355 (overloading boolean operations) and chained comparisons

Sven Marnach sven at marnach.net
Thu Oct 20 16:27:08 CEST 2011


Mike Graham wrote:
> I do, however, regularly write "(a < b) & (b < c)" and hate it; a
> little observation reveals is it quite terrible.

It might not be the nicest syntax ever, but I still find this quite
readable.  Of course 'a < b < c' looks nicer, but it's not that big a
deal.

> That being said, I think the fault might be as much numpy's as
> anything. An API like b.isbetween(a, c) or even (a < b).logicaland(b <
> c) would probably be nicer than the current typical solution.

Just for the record, NumPy already allows the syntax

    logical_and(a < b, b < c)

Cheers,
    Sven



More information about the Python-ideas mailing list