让我们运行以下代码:
st = {3, 1, 2} st >>> {1, 2, 3} st.pop() >>> 1 st.pop() >>> 2 st.pop() >>> 3
尽管集合被认为是无序的,但该集合的行为就像按升序排序一样。pop()根据文档,该方法应该返回“任意元素”,也按升序返回元素。这是什么原因呢?
pop()
python set unordered python-3.x python-3.9
python ×1
python-3.9 ×1
python-3.x ×1
set ×1
unordered ×1