加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

比较python中的两个布尔表达式

发布时间:2020-12-20 12:01:14 所属栏目:Python 来源:网络整理
导读:In[19]: x = NoneIn[20]: y = "Something"In[21]: x is None == y is NoneOut[21]: FalseIn[22]: x is None != y is None ## What's going on here?Out[22]: FalseIn[23]: id(x is None)Out[23]: 505509720In[24]: id(y is None)Out[24]: 505509708 为什么Ou
In[19]: x = None
In[20]: y = "Something"
In[21]: x is None == y is None
Out[21]: False
In[22]: x is None != y is None ## What's going on here?
Out[22]: False
In[23]: id(x is None)
Out[23]: 505509720
In[24]: id(y is None)
Out[24]: 505509708

为什么Out [22]是假的?他们有不同的ID,所以这不是身份问题….

解决方法

你的x是无!= y是无是“ chained comparisons”.更典型的例子是3< x<这意味着与(3
(x is None) and (None != y) and (y is None)

这是假的,因为y是None是假的.

)和(x>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读