conditional expressions
Bruce Dawson
bruce_deletethis_dawson at cygnus-software.com
Tue Sep 24 01:14:36 EDT 2002
Good point about the difference, and thanks for the pointer/reminder
about operator.truth. It's still good to have bool though - if only for
the compactness and readability of it.
Erik Max Francis wrote:
> Bruce Dawson wrote:
>
>
>>I find the (a and [b] or [c])[0] construct to obscure to be useful -
>>the
>>space it saves is wasted by the comment I have to put in to explain
>>it.
...
>
> I use this technique frequently enough, but this isn't really what a
> conditional expression does. A conditional expression only _evaluates_
> one of its consequents, depending on the value of the test expression.
> The (a, b)[operator.truth(p)] evaluates both.
>
> This is fine in many cases, of course -- such as when you're selecting
> between two strings -- but it isn't the full power of a true conditional
> expression.
>
>
More information about the Python-list
mailing list