Python - Set pop() Method


Advertisements

The Python set 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.

Example:

In the below example, 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)

Output

JAN
{'FEB', 'MAR', 'APR'}

Sets Methods




Advertisements