Python Set pop() Method

Example

Delete a random item from the set:

fruits = {"apple", "banana", "cherry"}
fruits.pop() 
print(fruits)

Run Instance

Definition and Usage

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

This method returns the deleted item.

Syntax

set.pop()

Parameter value

No parameter value.

More Examples

Example

Return the deleted element:

fruits = {"apple", "banana", "cherry"}
x = fruits.pop() 
print(x)

Run Instance

Note: The pop() method returns the deleted value.