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

Andrew Koenig ark at
Sat Feb 8 00:28:11 CET 2003

Steven> On 2/7/03 3:22 PM, "Gerrit Holl" <gerrit at> wrote:
>> IMHO, since else is obliged, 'x if a' is not allowed but 'x if a else None'
>> is, which is not intuitive.

Steven> I would agree here that "else" definitely should not be
Steven> obligatory.  The "else None" should be implied if the else is
Steven> missing.

But then you have to figure out the meaning of

        a if b if c else d

Does it mean

        (a if b) if c else d

which would be equivalent to

        (a if b else None) if c else d

or does it mean

        a if (b if c) else d

which would be equivalent to

        a if (b if c else none) else d

This ambiguity goes away if every "if" must have a corresponding "else".

Andrew Koenig, ark at,

More information about the Python-list mailing list