Check if a given value is out of certain range
Rustom Mody
rustompmody at gmail.com
Sun Oct 4 22:28:15 EDT 2015
On Sunday, October 4, 2015 at 7:18:11 PM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 3 Oct 2015 10:12 pm, Laura Creighton wrote:
>
> > Actually, the fact that adults have more difficulty processing
> > negations is one of the earliest things proven experimentally
> > in experimental psychology.
>
> I don't think I've questioned that under some circumstances some negations
> can be hard to understand. I've certainly written my share of code
> involving negatives that I've had to refactor to understand. A typical
> example:
>
> def function(arg, dontpreprocess=False):
> """Perform function on arg. If dontpreprocess is not true,
> arg is preprocessed."""
> if not dontpreprocess:
> arg = preprocess(arg)
> ...
>
> And of course there are the legendary chains of negations:
>
> don't not cancel the preprocessor suppressor
>
> Does the preprocess run or not? :-)
>
> But I don't think we can jump from a general observation about negations to
> the conclusion that a logical disjunction of two different comparisons is
> necessarily easier to understand than a negated chained comparison. Some
> negations are easy to understand:
>
> Don't touch that!
>
> and some negations may technically be harder to understand, but in a
> practical sense the difference may be negligible:
>
> if x == 1: ...
>
> if x != 1: ...
>
>
> I refuse to believe that the second is *significantly* harder to reason
> about than the first.
[With hermeneutic/semantic hat firmly on]
one could make a case that
"!=" ≠ "not =" ≠ "≠"
[Back with python hat]
My preference:
not 1 <= x <= 10
More information about the Python-list
mailing list