English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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()
The pop() method does not take any parameters.
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.
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.