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 Program to Shuffle Deck of Cards
Python Set difference_update()
Python locals()
Python Dictionary update()
Python sleep()
Python getattr()
Python *args and **kwargs
Python String zfill()
Python Program to Get the Class Name of an Instance
Python zip()
Python String rpartition()
Python Program to Count the Occurrence of an Item in a List
Python @property decorator
Python String casefold()
Python Program to Transpose a Matrix
Python String rindex()
Python Program to Capitalize the First Character of a String
Python repr()
Python String splitlines()
Convert a Map to an Array, List or Set in Java
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Find the Sum of Natural Numbers
Python List
Python hasattr()
Python Recursion
Python dict()
Intelligent Projects Using Python - Santanu Pattanayak
Python exec()
Python Program to Convert Decimal to Binary Using Recursion
Python globals()
Python List clear()
Python Program to Find Hash of File