Python Set - pop() Method
The Python pop() method is used to delete a random element from the set and returns the removed element.
Syntax
set.pop()
Parameters
No parameter is required.
Return Value
Returns the deleted element of the set.
Example:
In the example below, the pop() is used the set called MySet which deletes a random element from the set.
MySet = {'JAN', 'FEB', 'MAR', 'APR'} #deletes a random element from the set. x = MySet.pop() print(x) print(MySet)
The output of the above code will be:
APR {'MAR', 'FEB', 'JAN'}
❮ Python Set Methods