double equals vs在python中
发布时间:2020-12-20 10:32:16 所属栏目:Python 来源:网络整理
导读:参见英文答案 Is there a difference between “==” and “is”?????????????????????????????????????15个 ???????????? String comparison in Python: is vs. == ????????????????????????????????????4个 我在Python解释器中运行以下代码: foo = 10 dir
参见英文答案 >
Is there a difference between “==” and “is”?????????????????????????????????????15个
>???????????? String comparison in Python: is vs. == ????????????????????????????????????4个 我在Python解释器中运行以下代码: >>> foo = 10 >>> dir(foo) == dir(10) True >>> dir(foo) is dir(10) False >>> 为什么是这样? 解决方法
检查2个参数是否引用同一个对象,==检查2个参数是否具有相同的值. dir()返回一个列表,其中包含foo和10的相同数据,但两件事的实际列表实例是不同的.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |