Check if a given value is out of certain range

alister alister.nospam.ware at ntlworld.com
Wed Sep 30 16:19:31 EDT 2015


On Wed, 30 Sep 2015 21:06:02 +0300, Marko Rauhamaa wrote:

> Grant Edwards <invalid at invalid.invalid>:
> 
>>   not (0 <= x <= 10)         (I)
>> [...]
>>    (x < 0) or (x > 10)       (II)
>> [...]
>> IMO, (I) is _more_ readable than (II)
> 
> IMO, they're equally readable (except that you should drop the redundant
> parentheses from (II)).
> 
> 
> Marko

both are correct
the problem with 1 is the human brain is not particularity good with 
negatives*.
to do not (some function) you first of all have to work out some function 
& then invert it, a computer does this without difficulty the human brain 
gets confused which is why I personally consider ii is  more readable 
(YMMV especially if you are working with Boolean maths regularly) this 
example is relatively simple as things get more complex they become more 
error prone error.



*as an example you brain cannot correctly process the following.

Not (think of your left toe)

you are now thinking about it aren't you?


-- 
The UPS is on strike.



More information about the Python-list mailing list