对象
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
id | 140706631246736 |
---|---|
type | int |
value | 3 |
a
id | 140706631246736 |
---|---|
type | int |
value | 3 |
“我爱你”
id | 2139527386192 |
---|---|
type | str |
value | “我爱你” |
b
id | 2139527386192 |
---|---|
type | str |
value | “我爱你” |