Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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.

Return Value

Returns the deleted element of the set.

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)

The output of the above code will be:

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

❮ Python Set Methods