32. Problem to remove specific element from a set

In this Python set program, we will remove specific element from a set with the help of the below-given steps.

What is set?
Sets are used to store multiple items in a single variable.
The set is one of 4 built-in data types in Python used to store collections of data.
It is an unordered collection data type that is iterable, mutable and has no duplicate elements.

Remove specific element from a set:

Steps to solve the program

1. Create a set using {}.
2. Add some elements in the set.
3. Remove specific element from a set using the remove() function.
4. Print the set to see the result.

				
					a = {1,2,4,5}
print("Original set: ",a)
a.remove(5)
print("After removing 5 from the given set: ",a)
				
			

Output :

				
					Original set:  {1, 2, 4, 5}
After removing 5 from the given set:  {1, 2, 4}
				
			

Related Articles

find the common elements between two sets.

add multiple elements to a set.

Leave a Comment