Luke Paireepinart wrote: > Kent Johnson wrote: >> You can't generate all the float values in a range. (OK, you probably >> could, but it would not be practical or useful.) You can test for a >> value in a range, e.g. >> if 48.35 <= a <= 48.45: >> > Kent: > Why does this work?
It is explicitly supported in Python. See file:///C:/Python25/Doc/ref/comparisons.html which says, "Comparisons can be chained arbitrarily, e.g., x < y <= z is equivalent to x < y and y <= z, except that y is evaluated only once (but in both cases z is not evaluated at all when x < y is found to be false)." Kent > In C++ this would go from > > if (48.35 <= a <= 48.45) > > to (assuming the right condition is met) > > if (48.35 <= true) > > because it evaluates these things right to left, doesn't it? > does python treat chained comparisons differently than C++ or is C++ > behaving differently than I think it does? > Thanks for your help, > -Luke > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor