How to Use Set pop() Method in PythonPython Basics


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.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us