VOOZH about

URL: https://www.geeksforgeeks.org/python/python-set-remove-method/

⇱ Python Set - remove() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Set - remove() method

Last Updated : 23 Jul, 2025

Python remove() Function is a built-in method to remove elements from the set. remove() method takes exactly one argument.

Syntax

set.remove(element)

If the element passed to the remove() is present in the set then the element will be removed from the set. If the element passed to the remove() is not present in the set then KeyError Exception will be raised. The remove() method does not return any value.

Example 1:


Output
{1, 2, 3, 4, 5, 6, 7, 8, 9}
{1, 2, 3, 4, 6, 7, 8, 9}

Example 2:


Output
{1, 2, 3, 4, 5, 6, 7, 8, 9}
KeyError Exception raised
13 is not present in the set

resultant set : {1, 2, 3, 4, 5, 6, 7, 8, 9}
Comment
Article Tags: