<分区> 分区>
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]
