PEP 308 - ternary operator

Jim Jinkins j-jinkins at usa.net
Mon Feb 10 22:17:47 EST 2003


My preference for an immediate-if operator is the traditional '?' from C:

    cond ? expr1 : expr2

Yes this form is familiar only to C programmers, but there are a lot of 
us.  Yes it is one more use of the ':' operator, but Guido admits it is 
not ambiguous.  It also allows compact expressions of the form

    cond ? expr1 : cond ? expr2 : cond ? expr2 : ...

If this is not acceptable my second choice is a functional form:
    iif(cond, expr1, expr2)

This is not a function, it is a built-in macro.


    Jim Jinkins





More information about the Python-list mailing list