Python Set pop() MethodPython Functions

Difficulty Level:
Difficulty Level:

The pop() method removes and returns an arbitrary element from the set.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

Country1 = {"China", "India", "Japan","Mongolia","North Korea","South Korea"}
print(Country1)
Country1.pop()
print(Country1)
Country1.pop()
print(Country1)

Output:

{'China', 'India', 'Japan', 'North Korea', 'South Korea', 'Mongolia'}
{'India', 'Japan', 'North Korea', 'South Korea', 'Mongolia'}
{'Japan', 'North Korea', 'South Korea', 'Mongolia'}

Syntax

set.pop()

Parameters

The method doesn’t take any parameters.

Return Value

It returns the element removed.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us