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

Andrew Koenig ark at
Fri Feb 7 19:25:24 CET 2003

holger> What about a missing else clause? e.g. 

holger>         <expression> if <condition>

holger> Allowing it could be nice for stuff like 

holger>     result = obj(...) if callable(obj)

It's supposed to be an expression that yields a value.
So your example would be equivalent to

            result = (obj(...) if callable(obj))

and the question is:  What is the value of (x if y) when y is false?

I can't imagine any value that would do what you want.

In other words, I don't think we need a second way of writing

        if callable(obj): result = obj(...)

If you really want it, then say

        result = obj(...) if callable(obj) else result


        result = obj(...) if callable(obj) else None

or whatever else you want.

Andrew Koenig, ark at,

More information about the Python-list mailing list