Python Set discard() is an inbuilt function that removes any specified element from a set. The discard() method only removes an item that is present in the Set. The set discard() method is different from the set remove() method because the remove() method will raise the error if the specified item does not exist, whereas the discard() method will not raise any error.

Python Set discard()

Python inbuilt set method discard() removes an item from the set only if the item is present in the set. If the item is not present in the set, then no error or exception is raised, and the original set is returned.


It takes one argument called an element, which we want to remove from the set.

#python #python set discard

Python Set discard() Method Example
1.10 GEEK