python中的list和list[:]有什么区别?
问题描述:
python中list
和list[:]
有什么区别?
What, if any, is the difference between list
and list[:]
in python?
答
阅读时,list
是对原始列表的引用,而list[:]
浅-复制列表.
When reading, list
is a reference to the original list, and list[:]
shallow-copies the list.
分配时,list
(重新)绑定名称和 list[:]
切片分配,替换之前列表中的内容.
When assigning, list
(re)binds the name and list[:]
slice-assigns, replacing what was previously in the list.
另外,不要使用 list
作为名称,因为它会影响内置.
Also, don't use list
as a name since it shadows the built-in.