PEP 308 - ternary operator
Erik Max Francis
max at alcyone.com
Sun Feb 16 14:24:20 EST 2003
Nick Trout wrote:
> Has anyone pointed out that your can do ternary operators using:
>
> result = { 1: true_value, 0: false_value }[condition]
>
> or
>
> result = { 1: true_fn, 0: false_fn }[condition]()
>
> if they are functions.
This doesn't support short-circuiting, which is the key feature of a
true conditional operator. The PEP itself goes into great detail about
precisely what this feature is and why it's necessary.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ When one is in love, a cliff becomes a meadow.
\__/ (an Ethiopian saying)
Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
An Esperanto reference for English speakers.
More information about the Python-list
mailing list