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, then a op1 b op2 c ... y opN z
is equivalent
to a 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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…