Chained Comparisons

Fredrik Lundh fredrik at
Mon Mar 20 08:50:51 CET 2006

"Sathyaish" wrote:

> I) What does the following expression evaluate to?
> a < b == c
> 1) (a < b) and (b == c)
> 2) (a < b) or (b == c)

    Formally, if a, b, c, ..., y, z are expressions and opa, opb, ...,
    opy are comparison operators, then a opa b opb c ...y opy z
    is equivalent to a opa b and b opb c and ... y opy z, except
    that each expression is evaluated at most once.


More information about the Python-list mailing list