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 String isidentifier()
Python any()
Python List pop()
Python Generators
Java Program to Implement Dijkstra’s Algorithm using Set
Python Program to Convert Bytes to a String
Python Program to Return Multiple Values From a Function
Python String isupper()
Python List append()
Python input()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Check If Two Strings are Anagram
Python Iterators
Python RegEx
Python Program to Convert Decimal to Binary Using Recursion
Python list()
Python Decorators
Python Program to Delete an Element From a Dictionary
Python Program to Convert Two Lists Into a Dictionary
Python Variables, Constants and Literals
Python Program to Find the Sum of Natural Numbers
Python String format()
Python Objects and Classes
Python Dictionary pop()
Python String splitlines()
Python Program to Split a List Into Evenly Sized Chunks
Python String isnumeric()
Python min()
Python Program to Find HCF or GCD
Python Operator Overloading
Python String islower()
Python List count()