Python基础03 id

博客围绕Python编程展开,介绍了id函数可获取变量所引用对象的内存地址,is操作符用于比较对象身份标识,可看作id(a) == id(b),==操作符比较内容相等性。还提及True Value Testing、type和isinstance,其中isinstance支持继承,最后给出参考文档链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

id

id(x)对应变量x所引用对象的内存地址。可以把id(x)看成变量x的身份标识。

is

有时在编程中需要与变量的身份标识打交道,但不是通过 id 函数,而是 is 操作符。

The operators is and is not test for object identity: x is y is true if and only if x and are the same object.

可以简单把a is b 看成 id(a) == id(b)。

==

== 操作符也可用于相等性比较,只是比较的是内容的相等性,而不是身份标识的相等性。

True Value Testing

type && isinstance

isinstance支持继承

 

参考文档:

Determine the type of an object?

转载于:https://www.cnblogs.com/gattaca/p/7573661.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值