Proposed PEP for a Conditional Expression
s.keim at laposte.net
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" ":"
> 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
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