On Nov 25, 6:49 pm, Donn Ingle <[EMAIL PROTECTED]> wrote: > Sheesh, I've been going spare trying to find how to do this short-hand: > if 0 > x < 20: print "within" > > So that x must be > 0 and < 20. > > I usually do: > if x > 0 and x < 20: print "within" > > What's the rule? Does it even exist? > I read something like it recently on the list but can't find it, that's > where I got the urge to try it from. I can't find anything in the docs, but > then again (imho) the Python docs are like a tangled jungle... > > \d
The output of the following program might help: # chained_comparisons.py complist = '< <= == != >= >'.split() for lhs in complist: for rhs in complist: print "\n1 %2s x %2s 3:" % (lhs, rhs) for x in range(5): chain = " 1 %2s %i %2s 3" % (lhs, x, rhs) print chain," is ", eval(chain) - Paddy. -- http://mail.python.org/mailman/listinfo/python-list