Python Set remove() Method
Example
Remove "banana" from the set:
fruits = {"apple", "banana", "cherry"}
fruits.remove("banana")
print(fruits)
Run example »
Definition and Usage
The remove()
method removes the specified
element from the set.
This method is different
from the discard()
method, because the
remove()
method will raise an error if the specified item does not exist, and
the discard()
method will not.
Syntax
set.remove(item)
Parameter Values
Parameter | Description |
---|---|
item | Required. The item to search for, and remove |