Operator precedences

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Wed Feb 26 04:54:36 CET 2003


Jesper Hansen wrote:
> These both evaluate to true, so the order does not seem to be fixed;
> (3 < 2 < 1)  ==  (3 < (2 < 1))
> (1 < 2 < 3)  ==  ((1 < 2 ) < 3)
> 
> What am I missing?

Chained comparisons. In Python,

   a < b < c

is equivalent to

   a < b and b < c

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list