比较运算符和'is'-Python中的运算符优先级?

基杜斯

所以我在网上看一些代码,遇到了一行(在286行):
if depth > 0 and best <= -MATE_VALUE is None and nullscore > -MATE_VALUE:

我难以理解的部分是best <= -MATE_VALUE is None

因此,我启动了解释器,以查看诸如此类的语句的value1 > value2 is value3工作方式。
所以我尝试了

>>> 5 > 2 is True
False

>>> (5 > 2) is True 
True

>>> 5 > (2 is True) 
True


我的问题

为什么5 > 2 is TrueTrue呢?这些东西通常如何工作?

谢谢。

泥fish

您正在看到python的运算符链接工作

5 > 2 is True

相当于

5>2 and 2 is True

您可以在其中看到

>>> 5>2 is 2

返回True

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章