Table of Contents
The pop() method removes an arbitrary element from the set and returns the element removed.
The syntax of pop() for sets is:
set.pop()
1. pop() Parameters
The pop() method doesn’t take any arguments.
2. Return Value from pop()
The pop() method returns an arbitrary (random) element from the set. Also, the set is updated and will not contain the element (which is returned).
If the set is empty, TypeError exception is raised.
3. Example: How pop() works for Python Sets?
A ={'a', 'b', 'c', 'd'}
print('Return Value is', A.pop())
print('A = ', A)
When you run the program, we got the following output
Return Value is d
A = {'a', 'b', 'c'}
Note: You may get different output as
pop()returns and removes a random element.
Related posts:
Python setattr()
Convert a Map to an Array, List or Set in Java
Python Program to Sort Words in Alphabetic Order
Python Program to Print Hello world!
Python Program to Randomly Select an Element From the List
Python Set intersection()
Python Program to Find Hash of File
Python hex()
Python Program to Create a Countdown Timer
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Find the Sum of Natural Numbers
Python Set discard()
Python Tuple
Python Program to Find the Factors of a Number
Python Program to Differentiate Between del, remove, and pop on a List
Python oct()
Python sorted()
Python Program to Merge Two Dictionaries
Python Deep Learning Cookbook - Indra den Bakker
Python Input, Output and Import
Python sleep()
Python List
Python Program to Swap Two Variables
Deep Learning in Python - LazyProgrammer
Python next()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python min()
Python ord()
Python Sets
Python Program to Append to a File
Python format()