Python set remove is one of the set method, which is used to remove an item from the given set. In this article, we will show you, How to use this Python remove set function with practical examples.
TIP: Please refer sets article to understand everything about Sets.
Python set remove syntax
The basic syntax behind this remove function is:
set_Name.remove(element)
Python set remove Example 1
The set remove function helps you to remove any item from a given set. This is very useful function, if you know the item name that you want to delete. Below code removes or delete 30 from an integer set called removeSet
# 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)
OUTPUT
Let me show you another set remove method example. So that, you can get the complete idea.
How to remove set item in Python Example 2
In this example, we declared a string set. Next, we used this set remove function on the string set. Here, remove function will remove 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)
OUTPUT
Thank You for Visiting Our Blog