1
czheo 2017-01-21 11:28:23 +08:00 1
性能优化,内部把 list 重用了吧。
|
2
imn1 2017-01-21 11:31:24 +08:00
id([1]) is id([2])
|
4
czheo 2017-01-21 11:46:26 +08:00
tuple 是 immutable 的,没法重用
|
6
bxb100 OP @czheo list 是临时对象,内存会自动清理, tuple 不会,而且 ()和(1)存放地址区域不同
|
7
HypoChen 2017-01-21 19:20:03 +08:00 1
id(object)
Return the “ identity ” of an object. This is an integer (or long integer) which is guaranteed to be unique and constant for this object during its lifetime. **Two objects with non-overlapping lifetimes may have the same id() value.** ``` >>> id([1]) 4391579520 >>> id([2]) 4391579520 >>> a = [1] >>> b = [1] >>> id([1]) 4391757944 >>> id([2]) 4391757944 >>> id(a) 4391579520 >>> id(b) 4391641672 >>> id([]) 4391757944 ``` |