else on the same line - howto
Terry Reedy
tjreedy at udel.edu
Wed Oct 15 10:40:20 EDT 2003
"Helmut Jarausch" <jarausch at remove.igpm.rwth-aachen.de> wrote in
message news:bmj859$iph$1 at nets3.rz.RWTH-Aachen.DE...
> Since Python lacks conditional expression
> like
>
> k+= (dy >= 0 ? 1 : -1)
For this specific example:
k+= (dy >= 0 and 1 or -1)
But don't do this unless and until you 1) understand why this works
and why the and branch must be non-null and what happens if it is null
(this is discussed both in the FAQ and PEP 308) AND 2) accept
responsibility for always remembering the caution.
Terry J. Reedy
More information about the Python-list
mailing list