今天做leetcode算法题的时候,遇到了两个比较有意思的地方。特此记录。
In [1]: a=[1,2,3]
In [2]: id(a[:].extend([4]))
Out[2]: 1892525200
In [3]: id(None)
Out[3]: 1892525200
In [1]: a=[1,2,3,4,5,6,7]
In [2]: id(a)
Out[2]: 2168499537032
In [3]: id(a[:])
Out[3]: 2168499546056
In [4]: a[:]=[7,6,5]
In [5]: a
Out[5]: [7, 6, 5]
In [5]: id(a)
Out[5]: 2168499537032