In [ 1 ]: l = [ 1 , 2 , 3 ] In [ 2 ]: id ( l ) Out [ 2 ]: 2330596352328 In [ 3 ]: l *= 2 In [ 4 ]: l Out [ 4 ]: [ 1 , 2 , 3 , 1 , 2 , 3 ] In [ 5 ]: id ( l ) Out [ 5 ]: 2330596352328 In [ 6 ]: t = ( 1 , 2 , 3 ) In [ 7 ]: id ( t ) Out [ 7 ]:
In [2]: id(l)
Out[2]: 2330596352328
In [3]: l *= 2
In [4]: l
Out[4]: [1, 2, 3, 1, 2, 3]
In [5]: id(l)
Out[5]: 2330596352328
In [6]: t = (1, 2, 3)
In [7]: id(t)
Out[7]: 2330596337272
In [8]: t *= 2
In [9]: t
Out[9]: (1, 2, 3, 1, 2, 3)
In [10]: id(t)
Out[10]: 2330594190536
- 可变对象上:原地增长
- 不可变序列:创建新对象