Python Set remove method with Example – Python Tutorial

1 year ago Lalit Bhagtani 0

In this tutorial, we will learn about python set remove method.
Python Set Remove

remove method :

This method is used to remove single element ( passed as an argument ) from the set object. If we try to remove an element, which does not exist in the set object. It will raises a KeyError.

Syntax : < Set Object >.remove( < Immutable Object > ) 


# create set object and assign it to variable s s = {1,2,3,4,5} # remove element 2 from the set object s.remove(2) # print all elements of set print(s) # remove element 6 from the set object s.remove(6)

References :-

  1. remove method Docs

That’s all for Python Set remove method. If you liked it, please share your thoughts in comments section and share it with others too.