当我将全局列表分配到本地列表并编辑此本地列表时,列表都会被编辑。是因为python中的列表是指针,类似于C中的数组吗?
>>> source = [(0, 5), (1, 5), (2, 5), (3, 5), (4, 5)]
>>> def s():
... source_queue = source
... while len(source_queue)>0:
... f(source_queue)
...
>>> def f(source_queue):
... (x,y) = source_queue.pop(0)
... print (x,y) in source
... print source,source_queue
...
>>> s()
输出:
False
[(1, 5), (2, 5), (3, 5), (4, 5)] [(1, 5), (2, 5), (3, 5), (4, 5)]
False
[(2, 5), (3, 5), (4, 5)] [(2, 5), (3, 5), (4, 5)]
False
[(3, 5), (4, 5)] [(3, 5), (4, 5)]
False
[(4, 5)] [(4, 5)]
False
[] []