最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

python中id是什么意思

来源:动视网 责编:小OO 时间:2023-05-12 10:11:14
文档

python中id是什么意思

Python官方文档给出的解释是。id(object)Return the “identity” of an object.This is an integer (or long 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。由此可以看出。
推荐度:
导读Python官方文档给出的解释是。id(object)Return the “identity” of an object.This is an integer (or long 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。由此可以看出。


Python官方文档给出的解释是

id(object)Return the “identity” of an object. This is an integer (or long 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.

由此可以看出:

1、id(object)返回的是对象的“身份证号”,唯一且不变,但在不重合的生命周期里,可能会出现相同的id值。此处所说的对象应该特指复合类型的对象(如类、list等),对于字符串、整数等类型,变量的id是随值的改变而改变的。

2、一个对象的id值在CPython解释器里就代表它在内存中的地址。(CPython解释器:http://zh.wikipedia.org/wiki/CPython)

class Obj(): def __init__(self,arg): self.x=arg if __name__ == '__main__': obj=Obj(1) print id(obj) #32754432 obj.x=2 print id(obj) #32754432 s="abc" print id(s) #1401904453184 s="bcd" print id(s) #32809848 x=1 print id(x) #15760488 x=2 print id(x) #157604

文档

python中id是什么意思

Python官方文档给出的解释是。id(object)Return the “identity” of an object.This is an integer (or long 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。由此可以看出。
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top