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 Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Set remove()
Learning scikit-learn Machine Learning in Python -  Raul Garreta & Guillermo Moncecchi
Python filter()
Python Dictionary setdefault()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python sleep()
Python all()
Python next()
Python Set symmetric_difference()
Python id()
Python while Loop
Python Program to Find ASCII Value of Character
Python Program to Return Multiple Values From a Function
Python Program to Find the Largest Among Three Numbers
Python globals()
Python Program to Slice Lists
Python String rjust()
Python datetime
Python Program to Check the File Size
Python ord()
Python Program to Convert Kilometers to Miles
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python String isdecimal()
Python Program to Find HCF or GCD
Python String rstrip()
Python String isnumeric()
Python any()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Dictionary values()
Python List copy()
Python List