Proposed PEP for a Conditional Expression

sebastien s.keim at
Mon Sep 10 13:56:58 CEST 2001

>      SPEC_4: Use "if c: a else: b".
>          The following production would be added to Python syntax:
>              expression: "if" expression ":" expression "else" ":"
>                          expression
>          The famous "dangling-else" problem would NOT arise because
>          the "else:" part would be mandatory.
>          PRO - [might allow "if c1: a elif c2: b else: c"]
>          CON - [elif thing would re-introduce dangling else problem]

If think that this option has a killer PRO argument:
It's the syntax that anyone who already know the current if construct
in python
would try in first attempt.
That's because this syntax is the only one which is coherent with the
langage and don't introduce new concept but only extend an existing

That's why I'm agree for conditionnal expression with this syntax but
absolutly against the C ternary operator syntax. The over ones are
even worst because they are subbtle fluctations of the python standard
if construct and a potential source of confussion.

More information about the Python-list mailing list