在像下面这样的交互式 session 中:
>>> f=open('test.txt','w')
>>> f
<open file 'test.txt', mode 'w' at 0x6e610>
0x6e610 代表什么,我可以用 Python 中的十六进制数做什么?
最佳答案
>>> f=open('test.txt')
>>> f
<open file 'test.txt', mode 'r' at 0x10047c938>
>>> hex(id(f))
'0x10047c938'
看看id in the official documentation :
返回对象的“身份”。这是一个整数(或长整数),保证此对象在其生命周期内是唯一且不变的。两个生命周期不重叠的对象可能具有相同的 id() 值。
关于python - 什么代表 Python 中 print/repr 上显示的十六进制整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2556799/