Proposed PEP for a Conditional Expression

Terry Reedy tjreedy at home.com
Fri Sep 14 23:21:14 CEST 2001


<James_Althoff at i2.com> wrote in message
news:mailman.1000491857.7594.python-list at python.org...
> Why not just start with something simple like a builtin "cond"
function
> approximating the following:
> >>> def cond(expr, iftrue, iffalse=lambda:None):
> ...   if expr: return iftrue()
> ...   return iffalse()

Because, as explained before, both iftrue and iffalse expressions are
always both evaluated, which defeats one of the purposes of
conditional expressions, which is to not evaluate expressions that
will raise an exception.

Terry J. Reedy






More information about the Python-list mailing list