Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Set remove() Method

Python Set remove() Method

Python3 Lists Python Sets


Description

The remove() method removes a specified element from a set.

This method differs from the discard() method, because the remove() method raises an error when removing an element that does not exist, while the discard() method does not.

Syntax

Syntax of the remove() method:


set.remove(item)

Parameters

Return Value

No value is returned.

Example

Remove the element banana:

Example 1

fruits

= {

"

apple

"

,

"

banana

"

,

"

cherry

"

}

fruits

.

remove

(

"

banana

"

)

print

(

fruits

)

The output is:


{'cherry', 'apple'}

Python3 Lists Python Sets