好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

double equals vs在python中

参见英文答案 > 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的相同数据,但两件事的实际列表实例是不同的.

查看更多关于double equals vs在python中的详细内容...

  阅读:21次