Easy Tutorial
❮ Python Data Structure Python Att Dictionary Pop ❯

Python Set pop() Method

Python Set


Description

The pop() method is used to remove an element randomly.

Syntax

The syntax for the pop() method:

set.pop()

Parameters

Return Value

Returns the removed element.

Example

Removing an element randomly:

Example 1

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

fruits.pop()

print(fruits)

Output:

{'apple', 'banana'}

Outputting the return value:

Example 1

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

x = fruits.pop()

print(x)

Output:

banana

Python Set

❮ Python Data Structure Python Att Dictionary Pop ❯