Replace a list in Python
Replace a list in Python:1
2
3
4
5
6
7
8
9l = [1,2,3]
id(l)
4430796704
l = [2,3]
id(l)
4430918072
l[:] = [1,2,3]
id(l)
4430918072
The first way will change the id of the named list, while in the second way, only elements in the list are changed.