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