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 RegEx
Python Program to Find Armstrong Number in an Interval
Python Data Structures and Algorithms - Benjamin Baka
Python bytearray()
Python Program to Display Calendar
Python String partition()
Python iter()
Python Input, Output and Import
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Dictionary copy()
Python Decorators
Python String format_map()
Python Set union()
Python Program to Find the Largest Among Three Numbers
Python Program to Check Leap Year
Python ascii()
Python List remove()
Python String rsplit()
Python Dictionary
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Find LCM
Python input()
Python Get Current time
Python String upper()
Python @property decorator
Python Set difference()
Python frozenset()
Python String istitle()
Python String isdigit()
Python Program to Represent enum
Python List clear()
Python set()