Proposed PEP for a Conditional Expression

Terry Reedy tjreedy at
Mon Sep 10 15:10:37 CEST 2001

"Christian Tanzer" <tanzer at> wrote in message
news:mailman.1000105331.31775.python-list at

>Conditional expressions provide some nice benefits totally unrelated
to lambdas.
> One example: with a trivial class, one can put expressions into
> directives, like
>   "Found %(number)d error%(if number == 1 : '' else : 's')s" %

Python does not evaluate expressions inside strings and I do not
expect it ever will.
However, this can be rewritten today as

 "Found %(number)d error%s" % (num, num != 1 and 's' or '')

Terry J. Reedy

More information about the Python-list mailing list