Python Set - remove() method Last Updated : 05 Nov, 2021 Comments Improve Suggest changes Like Article Like Report 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: Python3 numbers = {1,2,3,4,5,6,7,8,9} print(numbers) # Deleting 5 from the set numbers.remove(5) # printing the resultant set print(numbers) Output{1, 2, 3, 4, 5, 6, 7, 8, 9} {1, 2, 3, 4, 6, 7, 8, 9} Example 2: Python3 numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9} print(numbers) # passing an element that is not in set # this will throw an KeyError exception try: numbers.remove(13) except Exception as e: print("KeyError Exception raised") print(e, "is not present in the set") # printing the resultant set print("\nresultant set : ", numbers) 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 More infoAdvertise with us Next Article Python Set - remove() method P pulamolusaimohan Follow Improve Article Tags : Python Python-Functions Practice Tags : pythonpython-functions Similar Reads Python | os.remove() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f 3 min read Python List remove() Method Python list remove() function removes the first occurrence of a given item from list. It make changes to the current list. It only takes one argument, element we want to remove and if that element is not present in the list, it gives ValueError.Example:Pythona = ['a', 'b', 'c'] a.remove("b") print(a 3 min read Python | os.removedirs() method OS module in Python provides functions for interacting with the operating system. OS comes under Pythonâs standard utility modules. This module provides a portable way of using operating system dependent functionality. All functions in os module raise OSError in the case of invalid or inaccessible f 3 min read Remove items from Set - Python We are given a set and our task is to remove specific items from the given set. For example, if we have a = {1, 2, 3, 4, 5} and need to remove 3, the resultant set should be {1, 2, 4, 5}.Using remove()remove() method in Python is used to remove a specific item from a set. If the item is not present 2 min read Python Set pop() Method Python set pop() removes any random element from the set and returns the removed element. In this article, we will see about the Python set pop() method. Example Input: {9, 1, 0} Output: {9, 1} Explanation: By using set pop() method, a random element 0 is removed from the set and remaining set is re 2 min read Like