Python Set pop() Syntax

Syntax: set_obj.pop()

Parameter: set.pop() doesn’t take any parameter.

Return: Returns the popped element from the set

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 returned.

Similar Reads

Python Set pop() Syntax

Syntax: set_obj.pop() Parameter: set.pop() doesn’t take any parameter. Return: Returns the popped element from the set...

Set pop() Method in Python

Python Set pop() is a method in Python used to remove and return any random element from the set. As we all know, Sets are an unordered collection of unique elements, so there’s no guarantee which element will be removed and returned by the pop() method. If the set is empty, calling pop() will raise a KeyError....