The remove method
The remove method removes elements from a set. If the element is not in the set, an error will be returned. In the method parameter, we pass the element we want to remove.
Syntax
set.remove(what we remove)
Example
Let's remove the element 'a' from our set:
st = {'a', 'b', 'c'}
st.remove('a')
print(st)
Result of code execution:
{'b', 'c'}
Example
Now let's remove an element that is not in the set:
st = {'a', 'b', 'c'}
st.remove('e')
print(st)
After executing the code, we will get an error:
KeyError: 'e'