June 2017
Beginner
352 pages
8h 39m
English
Two methods are provided for removing elements from sets. The first, remove(), requires that the element to be removed is present in the set, otherwise a KeyError is given:
>>> k.remove(97)>>> k{128, 81, 37, 54, 12, 108}>>> k.remove(98)Traceback (most recent call last): File "<stdin>", line 1, in <module>KeyError: 98
The second method, discard(), is less fussy and simply has no effect if the element is not a member of the set:
>>> k.discard(98)>>> k{128, 81, 37, 54, 12, 108}
Read now
Unlock full access