我看到了这个问题here现在我很好奇。与 JS 中的 === 符号相比,is
运算符在 python 中的行为如何?
最佳答案
不,它们不一样。 Python 中的 is
检查两个对象在 Python 中是否具有相同的 id
,即。它们是相同的,即使在内存中也是如此。您可以做的检查是:
>>> a='foo'
>>> a is 'foo'
True
>>> id(a)
44434088
>>> id('foo')
44434088
>>> a=[1]
>>> a is [1]
False
>>> id(a)
45789792
>>> id([1])
4469824
关于javascript - Python中的 'is'关键字和JS中的===关键字一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38108484/