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
set.discard(item)

Parameters

ParameterDescription
item Required. The item to remove from the set.

Example

Python
components = {'memory', 'processor', 'SSD'}
components.discard('SSD')
print(components)

Output

{'processor', 'memory'}