Proposed PEP for a Conditional Expression

Christian Tanzer tanzer at
Mon Sep 10 08:42:16 CEST 2001

> Michael Chermside wrote:
> [excellent work snipped, as I just want to snipe on one point...]
> >              using it may require creating a temporary variable and
> >              splitting a formula into two lines, or replacing a lambda
> >              expression with a named function.
> I consider that replacing lambda forms with named functions, in Python, is 
> an *excellent* practice, which should be encouraged by all means necessary. 
>  If the lack of a conditional operator does indeed encourage people to 
> write more local def's and fewer lambdas, then (to me) that is the "killer 
> argument" for not introducing conditional operators.

Conditional expressions provide some nice benefits totally unrelated
to lambdas.

One example: with a trivial class, one can put expressions into format
directives, like

    "Found %(number)d error%(if number == 1 : '' else : 's')s" % trivial

This doesn't look too attractive if used in a one-liner, put could be 
put to very good use for substitution in bigger templates.

Christian Tanzer                                         tanzer at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92

More information about the Python-list mailing list