How does set pop() work in Python?

The built-in pop() method in Python is used to remove a random item from the set that calls the method.

Syntax

set.pop()

Parameters and return value

This method does not require any parameters. The value it returns is the random item that it removes from the set that calls the method.

Example

x = {'Cats', 'Dogs', 'Elephants', 'Seals'}
y = x.pop()
print(x)
print(y)

Free Resources