PEP 308: Alternative conditional operator forms -- Corner Case solved

Bengt Richter bokr at
Wed Feb 12 22:54:37 CET 2003

On Wed, 12 Feb 2003 09:27:47 -0800 (PST), Dave Brueck <dave at> wrote:

>On Wed, 12 Feb 2003, Michele Simionato wrote:
>> I must say that even if initially I said "if C: x else: y" is ugly but
>> better than nothing, in the last few days the arguments of Samuele and
>> others finally convinced me that "nothing" is better than such a
>> confusion between expressions and statement. It seems to me absolutely
>> contrary to the Python design philosophy.
>Just bear in mind that "do nothing" also means "stay with the current
>idiom that in some cases doesn't work" (yeah, you can hear my bias in that
>statement ;-) ).
The current idiom can be made to work if we can mark the troublesome term
so that it will be treated as True in the logical expression, but will retain
its value. I am proposing {x} to mean treat x as true that way.

    c and {x} or y

is guaranteed to work as a ternary, and you can optionally write

    c and {x} or {y}

for stylistic symmetry if you like.

Bengt Richter

More information about the Python-list mailing list