pop()用于返回集合中 的元素,remove用来移除元素
现在试试:
s={1,2,3}
s.pop()
结果为1
但使用remove()时出错:
s.remove(2)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
s.remove(2)
KeyError: 2
报错原因是2不在集合中
那么让我们看看s
s={1,2,3}
>>> s.pop()
1
>>> s
{2, 3}
集合中有2这个元素,那么是哪里出错了?