PEP308 - preference for 'x if c else y' over 'c then x else y'

Roy Smith roy at panix.com
Sat Feb 15 12:06:47 EST 2003


"Terry Reedy" <tjreedy at udel.edu> wrote:
> While I was one of the people initially objecting to the order
> reversal, it *is* a common practice in mathematical writing to put
> conditions on the right of the values they select.  One can commonly
> see things like
>   abs(x) =  x    : x >= 0
>                 -x    : x <= 0
> So
>      return (x if c1 else
>                 y if c2 else
>                 z)
> really will be readable to many people, especially when reminded of
> the math language precedent.

But, anybody who knows the math notation, will read the ":" as "for", 
not as "if".




More information about the Python-list mailing list