Remove Item
To remove an item in a set, use the remove()
, or the discard()
method.
Example
Remove “banana” by using the remove()
method:
thisset = {"apple", "banana", "cherry"}
thisset.remove("banana")
print(thisset)
Note: If the item to remove does not exist, remove()
will raise an error.