1 > 0 == True -> False

Roy Smith roy at panix.com
Thu Jan 30 09:08:58 EST 2014


In article <3dcdc95d-5e30-46d3-b558-afedf9723c7c at googlegroups.com>,
 Thibault Langlois <thibault.langlois at gmail.com> wrote:

> You are right. I should have given some context.
> I am looking at this from the perspective of the teacher that has to explain 
> idiosyncrasies of the language to inexperienced students.
> There are two aspects in this example. 
> 1. the equivalence of True/False with integers 1/0 which have pro and cons.
> 2. the chaining rules of operators. I agree that it may make sense in some 
> cases like x > y > z but when operators are mixed it leads to counter 
> intuitive cases as the one I pointed out.
> 
> The recommendations to student are 1) do not assume True == 1 and do not use 
> operator chaining.

Better than that, do what I do.

1) Assume that you don't have the full operator precedence table 
memorized and just parenthesize everything.

2) In cases where the expression is so simple, you couldn't possibly be 
wrong, see rule #1.



More information about the Python-list mailing list