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 Inheritance
Python String count()
Python __import__()
Python Program to Count the Number of Occurrence of a Character in String
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String translate()
Java Program to Implement Dijkstra’s Algorithm using Set
Python Program to Iterate Over Dictionaries Using for Loop
Python List extend()
Python String isidentifier()
Python String isupper()
Python Program to Check Whether a String is Palindrome or Not
Python open()
Python Program to Check If a String Is a Number (Float)
Python list()
Python String zfill()
Python Program to Return Multiple Values From a Function
Python Set intersection()
Python Program to Find the Factorial of a Number
Python Program to Get the Class Name of an Instance
Python vars()
Python Program to Sort Words in Alphabetic Order
Python Set remove()
Python Set symmetric_difference_update()
Python Operators
Python float()
Python Program to Transpose a Matrix
Python Custom Exceptions
Python String isalnum()
Python String join()
Python Program to Convert Decimal to Binary Using Recursion
Python Program to Make a Simple Calculator