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 Remove Punctuations From a String
Python String casefold()
Python Operator Overloading
Python Program to Find Factorial of Number Using Recursion
Python eval()
JavaScript Map and Set
Python delattr()
Python Program to Check if a Key is Already Present in a Dictionary
Python String rjust()
Python Type Conversion and Type Casting
Python Program to Check if a Number is Positive, Negative or 0
Python Dictionary copy()
Python format()
Python classmethod()
Python Tuple index()
Python Dictionary setdefault()
Python float()
Python hex()
Python String lower()
Python Program to Create a Long Multiline String
Python Inheritance
Python Program to Find Armstrong Number in an Interval
Python String istitle()
Python Program to Reverse a Number
Python Program to Slice Lists
Python Get Current time
Converting Between a List and a Set in Java
Python Namespace and Scope
Python String join()
Python Program to Check Armstrong Number
Python filter()
Python ascii()