conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour))

Anders J. Munch andersjm at dancontrol.dk
Tue Oct 16 04:12:13 EDT 2001


"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1003176136.32708.python-list at python.org...
> For anyone keen to play with this, Guido has uploaded a patch.  It
> requires surrounding parens in fewer places than has been discussed so
far:
>
>
<http://sf.net/tracker/index.php?func=detail&aid=471421&group_id=5470&atid=3
05470>
>


"""It's hairier than expected because I'm trying to
require you to put parentheses around it in some cases
but not in others."""

For simplicity and consistency I think mandatory parentheses are
better.

Combine that with the form mentioned (though not preferred) by Michael
Abbott elsewhere we get:

    x = (if e1: e2 else: e3)

No new keyword, consistent with if-statement syntax and hence more
intuitive to someone who knows Python but not a heap of other
languages as well.  And it's slightly more terse than the if-then-else
form, which is important because terseness is the only reason to use a
conditional expression in the first place.

- Anders






More information about the Python-list mailing list