The discard method
The discard method removes elements that are in the set. If there is no element, then the original set will simply be returned. Unlike the remove method, which returns an error. In the method parameter, we pass the element we want to remove.
Syntax
set.discard(what to delete)
Example
Let's remove the element 'a' from our set:
st = {'a', 'b', 'c'}
st.discard('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.discard('e')
print(st)
After executing the code, we will get back the original array:
{'a', 'b', 'c'}