Does this do what I think it does?
assert 1 < 2 < 3
I couldn\'t find any reference to this in the docs but I saw it in a high rep ans
This is documented in detail in the Expressions chapter of the documentation:
Comparisons can be chained arbitrarily, e.g.,
x < y <= z
is equivalent tox < y and y <= z
, except thaty
is evaluated only once (but in both casesz
is not evaluated at all whenx < y
is found to be false).Formally, if a, b, c, ..., y, z are expressions and op1, op2, ..., opN are comparison operators, then
a op1 b op2 c ... y opN z
is equivalent toa op1 b and b op2 c and ... y opN z
, except that each expression is evaluated at most once.Note that
a op1 b op2 c
doesn’t imply any kind of comparison between a and c, so that, e.g.,x < y > z
is perfectly legal (though perhaps not pretty).