Python 为什么不';t这些语句都返回';真的';?
因此,我在python中遇到了一些奇怪的行为:Python 为什么不';t这些语句都返回';真的';?,python,math,logic,theory,Python,Math,Logic,Theory,因此,我在python中遇到了一些奇怪的行为: >>> 2+1 is 3 True >>> 2000+1 is 2001 False 当使用大整数时,它没有使用正确的逻辑,这是为什么?is如果两个变量指向同一个对象,将返回True。这样就有了id In [21]: id(3) Out[21]: 15538056 In [22]: id(2+1) Out[22]: 15538056 In [23]: id(2001), id(2000+1) Out[23]
>>> 2+1 is 3
True
>>> 2000+1 is 2001
False
当使用大整数时,它没有使用正确的逻辑,这是为什么?
is
如果两个变量指向同一个对象,将返回True
。这样就有了id
In [21]: id(3)
Out[21]: 15538056
In [22]: id(2+1)
Out[22]: 15538056
In [23]: id(2001), id(2000+1)
Out[23]: (52399576, 54526360)