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 Convert Two Lists Into a Dictionary
Python Exception Handling Using try, except and finally statement
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Find ASCII Value of Character
Python Program to Count the Number of Digits Present In a Number
Python Set intersection()
Python chr()
Python Dictionary
Python Set add()
Python Program to Convert Bytes to a String
Python Program to Merge Mails
Python String lstrip()
Python Program to Add Two Numbers
Python slice()
Python int()
Python Program to Find Armstrong Number in an Interval
How to get current date and time in Python?
Python Global, Local and Nonlocal variables
Python String rstrip()
Python Dictionary pop()
Python Custom Exceptions
Python String isupper()
Python Tuple count()
Python id()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python open()
Python compile()
Python min()
Python next()
Python Anonymous / Lambda Function
Python Program to Find Sum of Natural Numbers Using Recursion
Python Deep Learning Cookbook - Indra den Bakker