擅长:python、mysql、java
<p>当你写作时</p>
<pre><code>org_list = ['y', 'c', 'gdp', 'cap']
</code></pre>
<p>创建list对象,并将其命名为“org_list”。</p>
<p>当你这样做的时候</p>
<pre><code>copy_list = org_list
</code></pre>
<p>你的意思是,“名称复制列表与组织列表所指的对象相同”。</p>
<p>如果列表只包含不可变类型,则可以通过</p>
<pre><code>copy_list = list(org_list)
</code></pre>
<p>但请注意,只有当列表对象是不可变的时,这才有效,因为它会创建一个浅层副本,即复制列表,但列表中的每个元素都不会重复。</p>
<p>如果您有一个列表列表,并且想要复制所有内容,则需要执行一个深度复制:</p>
<pre><code>import copy
org_list = ['y', 'c', ['gdp', 'rtd'], 'cap']
copy_list = copy.deepcopy(org_list)
</code></pre>