标签: python list tuples string-interning
不变性的一个好处是内存效率 例如
>>> a = "abcd" >>> b = "abcd" >>> a is b True >>> a = 1 >>> b = 1 >>> a is b True
然而,对于元组,似乎python从未尝试过做同样的事情。我想知道为什么?
>>> a = (1, 2) >>> b = (1, 2) >>> a is b False