例如:
Programs\pythonScript.py
我更改了状态,但没有更改current_state。如何保持current_state值等于(5,[1,2,3])而不是在python中删除3?
谢谢!
答案 0 :(得分:1)
一个选项是deepcopy
state
,因此它和current_state
引用不同的对象:
>>> from copy import deepcopy
>>> state = (5,[1,2,3])
>>> current_state = deepcopy(state)
>>> state[1].remove(3)
>>> state
(5, [1, 2])
>>> current_state
(5, [1, 2, 3])