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 map()
Python Program to Differentiate Between type() and isinstance()
Python List reverse()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python String rpartition()
Python Program to Sort Words in Alphabetic Order
Python Dictionary
Python getattr()
Python abs()
Python Sets
Python Program to Find Hash of File
Python Program to Find the Size (Resolution) of a Image
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python oct()
Python String istitle()
Python Program to Reverse a Number
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python complex()
Python pass statement
Python strptime()
Python Program to Display Fibonacci Sequence Using Recursion
Python String rindex()
Python Program to Convert Kilometers to Miles
Python Program to Iterate Over Dictionaries Using for Loop
Python vars()
Python String lstrip()
Python Exception Handling Using try, except and finally statement
Python Program to Capitalize the First Character of a String
JavaScript Map and Set
Python Matrices and NumPy Arrays
How to get current date and time in Python?
Python strftime()