删除元素。discard 在元素不存在时什么也不做,remove 则会抛出 KeyError。
discard
remove
KeyError
elem
None
s = {1, 2, 3} s.discard(5) s.remove(1) print(s)
{2, 3}