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 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. Items to be searched and deleted.