Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
python3
sets
communitycreator

How does set pop() work in Python?

Hassan Ahmed

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)

RELATED TAGS

python
python3
sets
communitycreator
RELATED COURSES

View all Courses

Keep Exploring