gpt4 book ai didi

python - 如何使 Python 列表在其切片被更改时可变

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:55 25 4
gpt4 key购买 nike

<分区>

Python 的切片操作创建列表指定部分的副本。如何传递父列表的一部分,以便当该部分发生变化时,父列表的相应部分也随之变化?

def modify(input):
input[0] = 4
input[1] = 5
input[2] = 6


list = [1,2,3,1,2,3]
modify(list[3:6])
print("Woud like to have: [1,2,3,4,5,6]")
print("But I got: " + str(list))

输出:

想要:[1,2,3,4,5,6]
但是我得到了:[1,2,3,1,2,3]

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