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

Andrew Koenig ark at research.att.com
Fri Feb 7 20:33:07 EST 2003


Ian> Of course, personally, I would find this expression to be
Ian> horrible even without the missing else.  I would never put two
Ian> if's in a statement without parenthesis to make it entirely clear
Ian> how to parse it.

As long as every if has an else, no parentheses are needed.
That's one argument for a mandatory "else".  Another is that
the default value of None is not obvious.  For example, wouldn't
you be tempted to think that

        x = if y then z

means the same as

        if y:
            x = z

rather than

        if y:
            x = z
        else:
            x = None

?

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark




More information about the Python-list mailing list