Home / Python / Reference / Set methods

Python set remove() method

Remove an item; error if it is missing.

Syntax

set.remove(item)

Raises KeyError if the item is not in the set. discard does not.

Parameters

itemthe value to remove

Return value

None

Example

Code

s = {1, 2, 3}
s.remove(2)
print(s)

Output

{1, 3}

Related

Learn it step by step in the free lesson Dictionaries & Sets, with exercises that check your answers.