链接“是”运营商 [英] Chaining "is" operators
问题描述
python支持链接是
运算符吗?
Does python support chaining is
operators, such as the following?
a = None
b = None
a is b is None
True
,一些文档引用会很好。
This outputs True
, some doc references would be nice.
推荐答案
任何归类为比较的运算符都可以链接。从语言参考:
Yes. Any operators classified as comparisons can be chained. From the language reference:
正式地,如果 , b , c ,..., >, , ,
是比较运算符,则 a op1 b op2 c ... y opN z
等价于
到 a op1 b和b op2 c和...
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.
比较运算符<
,>
, ==
> =
,< =
,<>
!=
,在Python 3中使用了一个常用的同义词),!=
,是
,不是
,在
在中。
The comparison operators are <
, >
, ==
, >=
, <=
, <>
(a little-used synonym for !=
, gone in Python 3), !=
, is
, is not
, in
, and not in
.
这篇关于链接“是”运营商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!