Python Set remove() Method
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
- item -- the element to remove
Return Value
No value is returned.
Example
Remove the element banana:
Example 1
fruits
= {
"
apple
"
,
"
banana
"
,
"
cherry
"
}
fruits
.
remove
(
"
banana
"
)
(
fruits
)
The output is:
{'cherry', 'apple'}
Python Sets