Conditional operator in Python?
Terry Reedy
tjreedy at home.com
Tue Sep 4 14:13:31 EDT 2001
<thp at cs.ucr.edu> wrote in message news:9n1r3l$at7$2 at glue.ucr.edu...
> Terry Reedy <tjreedy at home.com> wrote:
> : If you *know* that a will always evaluate as <true>, then 'x and a
or
> : b' works fine. All the rigamarole of tuples or lambdas is only
needed
> : to protect against the possibility of a evaulating as false. When
it
> : is not possible, said protection is not necessary.
...
> Agreed. That helps in this particular case, but:
> - Correctness depends on the second operand being nonzero, which
Which is what I said.
> is not determinable in the general case.
Which is implied by what I said. Actually, you only need to know that
one of the consequents is non-zero, since you can negate the condition
if necessary to put that one first.
> - It's still less aesthetic than the common ?: syntax.
Esthetics of and/or vs ?/: is pretty much one of opinion.
Common??: is specific to C and derivitives as far as I know.
Terry J. Reedy
More information about the Python-list
mailing list