The set represents an unordered collection of unique elements. Sets are mutable meaning that they can be modified by adding or removing elements once they are created.

The remove()  method is used to remove a specified element from the set if present. It raises a KeyError if the element does not exist.

myset.remove(x)
x The element to be removed.
myset = {0, 2, 3, 4, 6, 7, 8, 9}
myset.remove(3)
myset.remove(7)
myset.remove(9)

print(myset)

As mentioned above, a KeyError exception will be raised if the element to be removed is not present in the set.

myset = {0, 2, 4, 6}

#raises a KeyError exception
myset.remove(3)

remove() vs discard()

The set class also includes the discard() method which is similar to the remove() method. The only difference is that the discard() method simply does  not raise any exception if the element to be removed does not exist, it just does nothing.

myset = {0, 2, 4, 6, 7}

myset.discard(3)
myset.discard(5)
myset.discard(7)

print(myset)