Python Set discard() Method
Example
Remove "banana" from the set:
fruits = {"apple", "banana", "cherry"} fruits.discard("banana") print(fruits)
Definition and Usage
The discard() method removes the specified item from the set.
This method is different from the remove() method because if the specified item does not exist, the remove() method will raise an error, while the discard() method will not.
Syntax
set.discard(value)
Parameter Value
Parameter | Description |
---|---|
value | Required. The items to be retrieved and deleted. |