English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonction en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Usage and example of Python set pop()

Méthodes de collection en Python

The pop() method deletes an arbitrary element from the set and then returns the deleted element.

The syntax of pop() is:

set.pop()

pop() parameters

The pop() method does not take any parameters.

pop() return value

The pop() method returns and deletes an arbitrary (random) element from the set. In addition, the set will be updated and the element will be returned.

TypeError exception will be raised if the set is empty.

Example: How to use pop() in Python set?

A = {'a', 'b', 'c', 'd'}
print('Return value is', A.pop())
print('A = ', A)

When you run the program, we get the following output

The return value is 'd'
A = {'a', 'b', 'c'}

Note:Different outputs may be obtained when pop() returns and deletes a random element.

Méthodes de collection en Python