新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:pythonid()
id()函數(shù)返回唯一的 id,它顯示對(duì)象的標(biāo)識(shí),并且始終是一個(gè)整數(shù)。這種身份對(duì)于對(duì)象來說是唯一的,并且在其整個(gè)生命周期中是不變的。

創(chuàng)新互聯(lián)建站主營瓊中黎族網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app開發(fā),瓊中黎族h5小程序設(shè)計(jì)搭建,瓊中黎族網(wǎng)站營銷推廣歡迎瓊中黎族等地區(qū)企業(yè)咨詢
**id(object)** #Where object can be int, float, str, list, dict, tuple, etc.
id()參數(shù):
只接受一個(gè)參數(shù)。對(duì)象可以是 int、float、str、list、dict、tuple 等類型。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 目標(biāo) | 需要返回其標(biāo)識(shí)的對(duì)象。 | 需要 |
標(biāo)識(shí)()返回值
id()方法還返回變量或?qū)ο蟮臉?biāo)識(shí)。所有變量和文字值都是對(duì)象,因此它們都有不同的id()值。
| 投入 | 返回值 | | 變量或文字 | 唯一的整數(shù)。 |
Python 中id()方法的示例
示例 1:id()是如何工作的?
class Foo:
b = 5
dummyFoo = Foo()
print('id of dummyFoo =',id(dummyFoo))
輸出:
id of dummyFoo = 140343867415240
示例 2:獲取文字值的標(biāo)識(shí)
print("Id of 10 is: ", id(10))
print("Id of 10.5 is: ", id(10.5))
print("Id of 'Hello World' is: ", id('Hello World'))
print("Id of list is: ", id([1, 2, 3, 4, 5]))
輸出:
Id of 10 is: 8791113061
Id of 10.5 is: 3521776
Id of 'Hello World' is: 60430408
Id of list is: 5466244
示例 3:兩個(gè)相同值的標(biāo)識(shí)是相同的
num = 10
print("Id of num is: ", id(num))
print("Id of 10 is: ",id(10))
輸出:
Id of i is: 8791113061696
Id of 10 is: 8791113061696 當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)Python教程:pythonid()
文章起源:http://fisionsoft.com.cn/article/cojhoce.html


咨詢
建站咨詢
