Python 数据皆对象

Python 数据是对象

对象思想

Python 程序中的一切数据都是对象。对象包括自定义对象及基本的数据类型(如数值、字符串、列表、字典)等。

# coding=utf-8
__author__ = 'Z'

x = 1
y = 2
print('x:', x, id(x))
print('y:', y, id(y))

y = x
print('x:', x, id(x))
print('y:', y, id(y))

x = 5
print('x:', x, id(x))
print('y:', y, id(y))


运行结果:
('x:', 1, 30801560)
('y:', 2, 30801548)
('x:', 1, 30801560)
('y:', 1, 30801560)
('x:', 5, 30801512)
('y:', 1, 30801560)

Python中皆对象,参见官方文档

Assignments do not copy data — they just bind names to objects. The same is true for deletions: the statement del x removes the binding of x from the namespace referenced by the local scope.

附:id()函数

id(…) 返回对象的内存地址
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (Hint: it’s the object’s memory address.)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值