Home >>Python Set Methods >Python Set discard() Method
Python set discard() method is used to remove the specified item from the given input set. It is different from the remove() method because the remove() method will give an error if the specified item does not exist but this method will not.
Syntax:set.discard(value)
Parameter | Description |
---|---|
value | This is a required parameter. It defines the item to search for and remove. |
thisset = {"apple", "banana", "mango"}
thisset.discard("banana")
print(thisset)