checking if two things do not equal None

Roy Smith roy at panix.com
Sun Mar 30 04:39:45 CEST 2014


In article <mailman.8709.1396145720.18130.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> Chained comparisons where you're checking a single variable against
> two constants make perfect sense:
> 
> 2 < x < 5
> 
> Chained comparisons where you check a single constant against two
> variables don't, so much:
> 
> x < 2 < y

To me, chained comparisons make intuitive sense when they're all "<" (or 
"<=").  I just think back to junior high school algebra class, with the 
big number line above the blackboard.  Thus,

 a < b < c

means if you put a, b, and c on the number line, a is to the left of b, 
which is to the left of c.  I have no problem extending that to more 
than three values:

 a < b < c < d < e

still makes intuitive sense.  I have no particular problem with

 x < 2 < y

because it fits the same pattern.  But, if you show me

 a != None != b:

my brain just goes into overload.  Honestly, I don't even know what that 
means.  My brain keeps trying to stick a, None, and b on Mrs. Albaum's 
number line and keeps walking into the wall.  If you (the editorial you) 
tell me that my failure to grok that expression means I'm not fluent in 
Python, well then, guilty as charged.



More information about the Python-list mailing list