Another conditional expression candidate (PEP 308)

Paul Rubin http
Mon Feb 10 06:06:31 CET 2003

Alan Daniels <from_usenet at> writes:
> Am I missing something? The whole point of a ternary operator is to
> save you extra typing.

I don't think that's the whole point.

> This just seems to take everything you'd typically write and squish it
> into one line.

Yes, so you can pass it as a function arg or whatever.

> Also, I think this would also be VERY confusing to new users.

When you're done explaining metaclasses to new users, tell me if you
still think conditional expressions will confuse them too much.

> This would be legal syntax:
>     result = if cond: x else: y
> But this...
>     result = if cond:
>         x
>     else:
>         y
> ...would be illegal (it certainly is *now*, anyway). So to implement
> this would require changing the fact that "if" blocks are not
> expressions. Do I understand this correctly? Thanks.

You might have to use backslashes to escape the ends of the lines,
just like you sometimes have to do in long statements now.   

More information about the Python-list mailing list