gpt4 book ai didi

python - python 列表连接中的奇怪行为

转载 作者:太空狗 更新时间:2023-10-30 02:44:02 26 4
gpt4 key购买 nike

<分区>

我创建一个 Python 列表作为

>>> list1 = ['a', 'b', 'c']

并设置

>>> list2 = list1

现在我对 list1list2 执行两个类似的操作

>>> list1 = list1 + [1, 2, 3]
>>> list1
['a', 'b', 'c', 1, 2, 3]
>>> list2
['a', 'b', 'c']

>>> list2 += [1,2,3]
>>> list1
['a', 'b', 'c', 1, 2, 3]
>>> list2
['a', 'b', 'c', 1, 2, 3]

但是两种情况下的结果都不一样。这是什么原因?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com