Skip to main content
 首页 » 编程设计

python之什么代表 Python 中 print/repr 上显示的十六进制整数

2025年05月04日15kerrycode

在像下面这样的交互式 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() 值。