元祖的相对不可变性(The relative immutability of Yuanzu)

元祖与多数Python集合(列表、字典、集,等等)一样,保存的是对象的引用。如果引用的元素是可变的,即便元祖本身不可变,元素依然可变。也就是说,元祖不可变性其实是指tuple数据结构的物理内容(即保存的引用)不可变,与引用的对象无关。

备注:str、bytes和array.array等单一类型序列是扁平的,它们保存的不是引用,而是在连续的内存中保存数据本身(字符、字节和数字)。

————————

Yuanzu, like most Python collections (lists, dictionaries, sets, etc.), holds references to objects. If the referenced element is mutable, the element is still mutable even if the original ancestor is immutable. In other words, the immutability of Yuanzu actually means that the physical content (i.e. saved references) of tuple data structure is immutable, independent of the referenced object.

Note: STR, bytes and array Single type sequences such as array are flat. Instead of storing references, they store the data itself (characters, bytes and numbers) in continuous memory.