Python Set remove() Method

❮ Set Methods


Example

Remove "banana" from the set:

fruits = {"apple", "banana", "cherry"}

fruits.remove("banana")

print(fruits)
Try it Yourself »

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

❮ Set Methods

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.