Proposed PEP for a Conditional Expression

Paul Rubin phr-n2001 at nightsong.com
Wed Sep 12 22:20:16 EDT 2001


"Terry Reedy" <tjreedy at home.com> writes:
> > > I agree that the above is backwards.
> > > <cond> if <expr> else <expr>
> >
> > No! That sounds way too much like Forth!
> 
> It is exactly like C, whose ? : equivalent is the impetus for the
> proposed change.
> Of course, if you don't like the form of C's conditional expressions,
> you won't like its translation into Python.

How about switching the condition and first expression?

   abs = x if x>=0 else -x     # find absolute value

I think that's closer to the Python syntax for list comprehensions.



More information about the Python-list mailing list