Javatpoint Logo
Javatpoint Logo

Python Set remove() Method

Python remove() method removes an element elem from the set. It raises error KeyError if elem is not contained in the set. See the examples given below.



elem: element to be deleted.


It returns None but throws KeyError if the value does not found in the set.

Let's see some examples of remove() method to understand it's functionality.

Python Set remove() Method Example 1

Let's first see a simple example to remove an element from the set.


{1, 2, 3}
After removing element: 
 {2, 3}

Python Set remove() Method Example 2

It throws an error KeyError if the element is not available in the set. See the example.


KeyError: 22

Python Set remove() Method Example 3

This method can be easily implemented into program to perform some business logic. See an examplpe below.


{'a', 'c', 'i', 't', 'n', 'u', 'y', 's', 'd', 'o', 'r'}
{'a', 'i', 'u', 'o'}

Next TopicPython Set

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA