list1 = {1,2,3,4} list1.remove(4) print(list) # {1,2,3}
# it doesn't raise error if element doesn't exits in set thisset = {1, 2,3} thisset.discard(3) print(thisset)
s = {0, 1, 2} s.discard(0) print(s) {1, 2} # discard() does not throw an exception if element not found s.discard(0) # remove() will throw s.remove(0) Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 0
list.discard(item)
s = set() s.remove(x)