PEP 308 - ternary operator

Erik Max Francis max at alcyone.com
Sun Feb 16 15:12:49 EST 2003


Nick Trout wrote:

> I think the definition of short circuiting is a little blurred. I
> think it
> basically means you dont want to evaluate the to values before you
> return
> one of them, which I don't believe I'm doing in either case.

When you explicitly have to defer execution, like you did in the second
case, that doesn't qualify as short circuiting.  In short circuiting the
evaluation is implicit.

	result = {True: math.sqrt(x), False: 0}[x >= 0]

Even when you defer it with an explicit function call, the _value_ is
still executed, it's just that the value is now a function.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If a thing is worth doing, then it is worth doing badly.
\__/ G.K. Chesterton
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.




More information about the Python-list mailing list