Python set remove method

The Python set remove function removes an item from the given set. The syntax of the set remove function is:

set_Name.remove(element)

Python set remove Example

The set remove function helps to remove any item from a given set. The set remove function is very useful if we identify the item name that we want to delete. The below set remove code deletes 30 from an integer set called removeSet.

TIP: Refer to the Python set article in Python.

# Python set remove method

removeSet = {10, 25, 30, 45, 50}
print("\nOld Set Items = ", removeSet)

# Python Remove Set Item
removeSet.remove(30)
print("After Remove Method - Set Items = ", removeSet)
Python set remove method 1

How to remove a set item?

In this example, we declared a string set. Next, we used the set remove function on this string set. Here, remove function removes cherry from the fruits set.

# Python set remove method

removeSet = {'apple', 'Mango', 'cherry', 'kiwi', 'orange', 'banana'}
print("\nOld Set Items = ", removeSet)

# Python Remove Set Item
removeSet.remove('cherry')
print("After Remove Method = ", removeSet)

Old Set Items =  {'orange', 'banana', 'cherry', 'kiwi', 'apple', 'Mango'}
After Remove Method =  {'orange', 'banana', 'kiwi', 'apple', 'Mango'}