Another conditional expression candidate (PEP 308)

Roy Smith roy at
Mon Feb 10 04:34:09 CET 2003

Erik Max Francis <max at> wrote:
> Because in the statement form, the default "else" portion is to do
> nothing whatsoever.  In the expression, it can't do nothing; it has to
> do something.  I agree that if you _do_ want to make the "else" portion
> optional, None is the logical choice, but I don't see the pressing need
> for it to be optional in the first place.

The only pressing need is to try and keep things as uniform and 
orthogonal as possible.  The "if" statement doesn't need an else clause, 
and does nothing if the condition is not met.  A fuction doesn't need to 
end in a "return" statement, and returns None if it falls off the end.

Given those, it just seems logical that an ternary expression shouldn't 
need an else clause, and should return None if there isn't any.  
Granted, I suspect in almost every case where you'd want to return None 
as a default, putting in the explicit "else None" would be stylisticly 
better, it doesn't seem necessary to require it.

More information about the Python-list mailing list