You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: a = 'Test'
In [2]: b = 'Test'
In [3]: a is b
Out[3]: True
In [4]: a is 'Test'
Out[4]: True
In [5]: c = 'Test!'
In [6]: d = 'Test!'
In [7]: c is d
Out[7]: False
In [8]: c is 'Test!'
Out[8]: False
In [9]: print(id(a))
140400778717760
In [10]: print(id(b))
140400778717760
In [11]: print(id(c))
140400777527680
In [12]: print(id(d))
140400777530536
In [13]: c == d
Out[13]: True
In [14]: e = '!'
In [15]: f = '!'
In [16]: e is f
Out[16]: True
特殊字符不驻留
In [17]: print(id('Test!'))
140400777708800
In [18]: print(id('Test!'))
140400777710368
In [19]: print(id('Test!'))
140400776986552
In [20]: print(id('Test!'))
140400776969328
None是一个特殊的常量,不同的 None 的id是一样的。
In [8]: c = None
In [9]: print(id(c))
10306432
In [10]: print(id(None))
10306432
In [11]: c is None
Out[11]: True
对于整数对象,如果其值处于[-5,256]的闭区间内,则值相同的对象是同一个对象,否则为不同对象
In [26]: print(id(1))
10914496
In [27]: print(id(1))
10914496
In [28]: print(id(1))
10914496
In [29]: print(id(257))
140400778124592
In [30]: print(id(257))
140400779126896
In [31]: print(id(257))
140400778124592
In [32]: print(id(257))
140400779127536
In [33]: print(id(257))
140400778125104
The text was updated successfully, but these errors were encountered:
Reference
Brief
is
==
Example
None
是一个特殊的常量,不同的None
的id是一样的。The text was updated successfully, but these errors were encountered: