wartime
2016-04-18 00:05:17 +08:00
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.)
(a, b) 实际上是临时分配的一个变量,由于没有引用可能马上释放。
(1, 2) 和 ('string', 2) 如果凑巧在相同位置,看上去 id 值一样,实际上之前的已经释放,内容已经改变。
c = (a,b) = (1,2)
print id(c)
d = (a,b) = ("string",2)
print id(d)
在 c 和 d 的值不变的情况下, id(c) id(d)值不变 (tuple 是 immutable)