動作環境
ideone (Python 3.5)
@ Scipy Lecture notes, Edition 2017.1
p21 2.2.3 Assignment operator
@ Web版 1.2.2.3. Assignment operator
https://www.scipy-lectures.org/intro/language/basic_types.html#assignment-operator
In [6]: id(a)
Out[6]: 138641676
In [7]: a[:] = [1, 2, 3] # Modifies object in place
In [9]: id(a)
Out[9]: 138641676 # Same as in Out[6], yours will differ...
上記のようなaへの代入だとidentityは変更されないとのこと。
ideoneでもidentityは変更されなかった。
a = [1, 2, 3]
print(id(a))
a = [4, 5, 6]
print(id(a))
a[:] = [7, 8, 9]
print(id(a))
run
47713454781832
47713454783560
47713454783560
identityを変更しないことによる利点については未消化。