python函数示例_id()函数以及Python中的示例

python函数示例

Python id()函数 (Python id() function)

id() function is a library function in Python, it is used to get a unique identity number (id) of an object, it accepts an object (like int, float, string, list, etc) and returns unique id number.

id()函数是Python中的一个库函数,用于获取对象的唯一标识号(id),它接受一个对象(如int,float,字符串,列表等)并返回唯一的id号。

What is an Id?

什么是ID?

An Id is a memory address of each object, which is assigned while an object is created, all objects have their own unique identity number, that can be changed to execute the program again.

Id是每个对象的内存地址,在创建对象时分配该地址,所有对象都有自己的唯一标识号,可以更改该标识号以再次执行程序。

Syntax:

句法:

    id(object)

Parameter(s):object – an object like int, float, string, list, tuple etc.

参数: object –一个对象,例如int,float,string,list,tuple等。

Return value: float – it returns a unique identity number (which is in integer format) of given object.

返回值: float –返回给定对象的唯一标识号(整数格式)。

Example:

例:

    Input:
    a = 10  
    
    print("id(a): ", id(a))
    
    Output:
    id(a):  10455328

Python code to get id(s) of various type of objects

Python代码可获取各种类型的对象的ID

# python code to demonstrate example
# of id() function

a = 10          # integer variable
b = 10.23       # float variable
c = "Hello"     # string variable
d = [10, 20, 30, 40, 50]    # list variable 

# return type of id()
print("return type of id(): ", type(id(a)))

# getting id of objects

print("id(a): ", id(a))
print("id(b): ", id(b))
print("id(c): ", id(c))
print("id(d): ", id(d))

Output

输出量

First run:
return type of id():  <class 'int'>
id(a):  10455328
id(b):  139862812754400
id(c):  139862812332136
id(d):  139862811549960

Second run:
return type of id():  <class 'int'>
id(a):  10455328
id(b):  139836840616416
id(c):  139836840194152
id(d):  139836839411976


翻译自: https://www.includehelp.com/python/id-function-with-example.aspx

python函数示例

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值