Another conditional expression candidate (PEP 308)

Andrew Koenig ark at
Mon Feb 17 03:02:43 CET 2003

Bob> I'm a newbie.  That else jumped out at me.  It seems ambiguous.
Bob> What does this mean?

Bob> x = (if c1: e1 elif c2: (if c3: e3 else: e4))
Bob> or
Bob> x = (if c1: e1 elif c2: (if c3: e3) else: e4)

I think they should both be invalid.

Bob> Elsewhere in the thread you implied the latter.  I just wanted
Bob> to reinforce your point, and say this complex enough without having
Bob> to decipher which if/elif does that else belong to.

I don't see the problem, as long as you follow the following rules:

        1) Replace each "elif" by "else if"

        2) After (1), each "if" must have exactly one "else" that
           corresponds to it.

By implication, the number of "else" keywords must always be equal
to the number of "if" keywords, a state of affairs that does not
apply to either of the examples above.

Andrew Koenig, ark at,

More information about the Python-list mailing list