gpt4 book ai didi

python - 修改原始列表时如何使对象列表的副本不变?

转载 作者:太空狗 更新时间:2023-10-29 20:54:52 24 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
How to clone a list in python?
What is the best way to copy a list in Python?

original_list = [Object1(), Object2(), Object3()]
copy_list = original_list
original_list.pop()

如果我从原始列表中删除一个对象,我怎样才能防止副本列表也发生变化?

原始列表

[<Object.Object instance at 0x00EA29E0>, <Object.Object instance at 0x00EA2DC8>, <Object.Object instance at 0x00EA2EE0>]

弹出原始列表后复制列表(我希望它等于上面的内容)

[<Object.Object instance at 0x00EA29E0>, <Object.Object instance at 0x00EA2DC8>]

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