我正在尝试分配 a = x 和 b = x.pop();尽管我得到了意想不到的任务。你能解释一下吗?
>>> x = [10, 11, 12, 13]
>>> a, b = x, x.pop(2)
>>> print a
[10, 11, 13] # Shouldn't I get a = [10, 11, 12, 13]?
>>> print b
12
最佳答案
Since you're referring direct list, it's popping and assigning what left in list. If you have list as copy then try this:-
x = [10, 11, 12, 13]
a,b = x.copy(),x.pop(2)
print(a) # your expected output
关于python - 执行 list.pop() 时出现意外结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678044/