python中有一个内置函数叫id(obj) ,可以获取obj在python中的实际内存,比如:
>>> id(13)
8791398340000
>>> id(int)
8791397851616
那么,id(obj)和id(obj)是不是相等的呢?让我们来测试一下(Python3.7)
>>> id(13)
8791398340000
>>> id(13)
8791398340000
>>> id(int)
8791397851616
>>> id(int)
8791397851616
原来他们相等啊。。。不对!!id(257)和id(257)就不相等!
>>> id(257)
52174288
>>> id(257)
52174768
但是又有......
>>> id(257)==id(257)
True
这是为什么呢?大家可以参考一下Github上名叫What's The F*ck of python的文档,答案就在里面。
转载于:https://blog.51cto.com/13946759/2167294