else on the same line - howto

Peter Hansen peter at engcorp.com
Wed Oct 15 11:43:26 EDT 2003


Terry Reedy wrote:
> 
> "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.

Is it "non-null" or "non-false"?




More information about the Python-list mailing list