On Wednesday, July 16, 2014 11:41:49 AM UTC-7, Nils Bruin wrote:

> That's because "and" and "or" are program flow constructs in python, as 
> they are in C (they have "shortcut evaluation" behaviour. They are 
> equivalent to
>
> (x<2) if bool(x<2) else (x<1)
>
> and
>
> (x<2) if not(bool(x<2)) else (x<1)
>
> except that the "x<2" doesn't get evaluated twice.
>

My apologies: this should be the other way around. If (x<2) is false then 
there is no need to evaluate (x<1) to determine the result of "and" and 
hence the first value is returned. So the logic is "bool(x<2) == False" and 
hence "(x<2) and (x<1)" does not depend on the truth value of "(x<1)". 
Python has specified that the value of the first argument gets returned, 
rather than "False" explicitly, because that is the most versatile (albeit 
in this case confusing) behaviour.


-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to