链接“是”运营商 [英] Chaining "is" operators

查看:128
本文介绍了链接“是”运营商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 to a 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆