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. Please share it with others who want to learn Python programming.

Other set methods

For More Information:- Click Here

Python Set issubset() Method
Python Set remove() Method

Was this post helpful?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *