(6)对象的基本组成和内存表示

it2022-05-05  197

对象

python中,一切皆对象。对象由标识(identity)、类型(type)、值(value)组成。

标识用于唯一标识对象,通常对一个与对象在计算机中的内存地址;类型用于表示对象存储的“数据”的类型;值表示对象所存储的数据的信息。

对象的本质就是:一个内存块、拥有特定的值、支持特定类型的相关操作。 举例

>>> a=3 >>> a 3 >>> id(3) 140706631246736 >>> type(3) <class 'int'> >>> b="我爱你" >>> id(a) 140706631246736 >>> type(a) <class 'int'> >>> print(a) 3 >>> id(b) 2139527386192 >>> type(b) <class 'str'> >>>

3

id140706631246736typeintvalue3

a

id140706631246736typeintvalue3

“我爱你”

id2139527386192typestrvalue“我爱你”

b

id2139527386192typestrvalue“我爱你”

最新回复(0)