python中的list和list[:]有什么区别? [英] What is the difference between list and list[:] in python?
本文介绍了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.
这篇关于python中的list和list[:]有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文