python按值列出而不是按引用 [英] python list by value not by reference

查看:50
本文介绍了python按值列出而不是按引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们举个例子

a=['help', 'copyright', 'credits', 'license']
b=a
b.append('XYZ')
b
['help', 'copyright', 'credits', 'license', 'XYZ']
a
['help', 'copyright', 'credits', 'license', 'XYZ']

我想在列表'b'中附加值,但列表'a'的值也已更改.
我想我不知道为什么会这样(python通过引用传递列表).
我的问题是如何通过值传递它,以使添加'b'不会更改'a'中的值?"

I wanted to append value in list 'b' but the value of list 'a' have also changed.
I think I have little idea why its like this (python passes lists by reference).
My question is "how can I pass it by value so that appending 'b' does't change values in 'a' ?"

推荐答案

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆