Yes. Any operators classified as comparisons can be chained. From the language reference:
Formally, if a, b, c, …, y, z are expressions and op1, op2, …, opN
are comparison operators, thena 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.
The comparison operators are <
, >
, ==
, >=
, <=
, <>
(a little-used synonym for !=
, gone in Python 3), !=
, is
, is not
, in
, and not in
.