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 Check Leap Year
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Get Current time
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Set difference_update()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python String lstrip()
Python String rjust()
Python Program to Access Index of a List Using for Loop
Python Program to Check If a List is Empty
Python Functions
Python String ljust()
Python callable()
Python Machine Learning - Sebastian Raschka
Python delattr()
Python Program to Convert Kilometers to Miles
Python String isidentifier()
Python List pop()
Python String startswith()
Python Program to Make a Flattened List from Nested List
Python Program to Print the Fibonacci sequence
Python Program to Merge Two Dictionaries
Python Program to Swap Two Variables
Python Program to Add Two Matrices
Python eval()
Python Set copy()
Python Program to Safely Create a Nested Directory
Python Dictionary fromkeys()
Python datetime
Python Set remove()
Python Program to Measure the Elapsed Time in Python
Python strptime()