Removing elements from sets

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}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset