Python Set discard() Method
Removes the specified item from the set. If the item does not exist, no
exception is thrown. Compare this to the remove
method which will throw an exception if the item doesn't exist.
Syntax
Python
Copy Code
set.discard(item)
Parameters
Parameter | Description |
---|---|
item |
Required. The item to remove from the set. |
Example
Python
Copy Code
components = {'memory', 'processor', 'SSD'} components.discard('SSD') print(components)
Output
{'processor', 'memory'}