Menu Close

Python Set pop() Method

Python set pop

In this set method tutorial, we are going to learn how to use the set pop() method to remove items from the set.
Click here to learn all about sets in Python, before going through this tutorial.

Python Set pop() Method

Python set pop() method is used to removes the random item from the set and return the deleted item.The set pop function actually works with only sets in Python because it is a set method.

Syntax

Syntax of pop function in python is:-

set.pop()

Arguments

The python set pop method does not take any parameter.

Return Value

set pop function in python returns only removed value.

Python set pop example

In this we will randomly remove item from the set using set pop function.

Example:


set1 = {'Python', 'Java', 'JavaScript', 'C++'}
result = set1.pop()
print(result)

Output:


Javascript
{'Java', 'Python', 'C++'}

Conclusion

In this article, you have seen how to use the python set pop method to removes the random items from the set. This method removes only deleted items. I f you like this article, please share, support and keep visit for further Python tutorials.

Other set methods


For More Information:- Click Here

Thanks for reading…

Python Set union() Method
Python Set add() Method

Related Posts