A set
represents a collection of unordered, unique elements.
Sets are mutable meaning that
The discard()
method is used to
myset.discard(e)
copy
e |
The element to be removed. |
The discard()
method removes element e if it exists in the set, otherwise
The method does nothing if the method is not present.
discard() vs remove()
The set
class also includes the remove()
method which works similarly to discard()
except thatremove()
will raise an error if the element does not exist in the set, whereas discard()
will not.
The remove()
method raises a KeyError
exception if the input element dose not exist in the set.