THE WORLD'S LARGEST WEB DEVELOPER SITE

Python Set pop() Method

❮ Set Methods


Example

Remove a random item from the set:

fruits = {"apple", "banana", "cherry"}

fruits.pop()

print(fruits)
Run example »

Definition and Usage

The pop() method removes a random item from the set.

This method returns the removed item.


Syntax

set.pop()

Parameter Values

No parameter values.


More Examples

Example

Return the removed element:

fruits = {"apple", "banana", "cherry"}

x = fruits.pop()

print(x)
Run example »

Note: The pop() method returns removed value.


❮ Set Methods