For review: PEP 308 - If-then-else expression

Alex Martelli aleax at
Sun Feb 9 17:58:30 CET 2003

Piet van Oostrum wrote:
> What about:
>         condition -> (true part, false part)
> The (,) is not a tuple here but it belongs to the -> and the -> says to
> select one of the expressions based on the condition and evaluate that;
> kind of lazy indexing.
> We could then also have one for ints rather than bools:
>         i -> [ v_0, v_1, v_2, ... ]
> which would pick v_i and evaluate that.

This is the first syntax I've seen proposed for this that I _like_.

I particularly like the generalization to an int on the LHS of the
new proposed -> operator.  However, I am slightly troubled by the
subtly different syntax for the two-alternatives vs N-alternatives
usages.  Whatever kind of parentheses are used, couldn't the
number of alternatives listed inside the parentheses be the ones
that control whether the LHS is taken as int or condition?  Or
would that be unpythonic?  I don't feel very certain about this.


More information about the Python-list mailing list