问题
I'm curious about the difference and relationship between id(L) and id(L[:]), where L is a list.
The official documentation says this about id():
CPython implementation detail: This is the address of the object in memory.
But I don't understand why id(L) and id(L[:]) have different values.
回答1:
L[:] produces a copy of the list. Its a whole new list contain the same items as L. As a result, its stored in a different place in memory and has a different id.
来源:https://stackoverflow.com/questions/9475982/python-list-idl-and-idl