Python 内建函数 - id(object)

本文介绍了Python内置函数id(),它返回对象的唯一标识,确保在对象生命周期内不变。id()值基于对象的内存地址,在不同对象生命周期中可能会相同。了解这一CPython实现细节对理解Python内存管理至关重要。
摘要由CSDN通过智能技术生成

Manual

Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value.

CPython implementation detail: This is the address of the object in memory.

直译

返回object的“身份”,返回值为整数,是为了确保在对象的生命周期内的独特性和一致性,两个非重叠生命周期的对象可能有相同的id()值。
CPython实现细节:该值为对象的内存地址。

实例

>>> import os
>>> id(os)
44484096

>>> def foo(x):
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值