Check if a given value is out of certain range

Bartc bc at freeuk.com
Sat Oct 3 06:48:17 EDT 2015


On 03/10/2015 11:29, Steven D'Aprano wrote:
> On Fri, 2 Oct 2015 07:45 am, John Gordon wrote:

> I find this discussion about the relative readability of
>> not 0 <= x <= 10 #1
>> versus
>> 0 < x or x > 10 #2
> 0 < x or 10 < x
>> to be a good example of people's propensity to invent so-called "rational"
> justifications for irrational preferences. Honestly, all these people
> claiming that reading #1 takes them "slightly more effort" than reading #2,
> or vice versa. Really?

I find #1 straightforward (although I'm bothered by the lack of 
parentheses as I would parse that as (not 0). Presumably, this does 
actually mean not (0<=x<=10).)
But I spent a minute looking at #2, and I'm still not sure that it 
expresses the same thing. I would have written #2 as:
 x<0 or x>10
-- 
Bartc


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /