python list id(L) and id(L[:])

强颜欢笑 提交于 2020-02-24 17:54:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!