Home >>Python Set Methods >Python Set remove() Method

Python Set remove() Method

Python Set remove() Method

Python Set remove() Method in python set is used to remove the specified element from the given set. This method will raise an error if element does not exist in the set.

Syntax:
set.remove(item)

Parameter Values

Parameter Description
item It is Required. The specified item to be removed.
Here is an example of Python Set remove() Method:

lang = {"php", "python", "java"}
lang.remove("python") 
print(lang)

Output:
{'php', 'java'}
Example 2:

def Remove(colors): 
	colors.remove("red") 
	print (colors)  
colors = set(["blue", "red", "green", "yellow", "orange"]) 
Remove(colors)

Output:
{'yellow', 'orange', 'green', 'blue'}

No Sidebar ads