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

Alex Martelli aleax at
Mon Feb 10 00:00:01 CET 2003

Georg Mischler wrote:
>> We have an important precedent in Python, in the form of list
>> comprehension, where `if' and `for' are appended to the expression.
> And that's why I'm really glad that list comprehensions *require*
> the [brackets] around them. They tell the reader that there is
> something slightly unusual going on inside. In a way, list
> comprehensions are a seperate language within the language.
> In contrast, the strange sequence of conditional and expressions
> proposed in this PEP can almost appear anywhere in the code
> without the slightest visual warning. That looks like very
> dangerous territory to me.

So maybe the syntax should be:

    [whentrue if condition else whenfalse]

i.e., just like in the PEP *BUT* with brackets around it.  Minus: the
brackets suggest "list" and there's no list here.  Pluses: remove the
"can almost appear anywhere", add the "tell the reader", exploit the
"trailing if" habit from LC's -- the lack of any 'for' clause should be
sufficient to distinguish this from LC's, I think.


More information about the Python-list mailing list