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 swapcase()
Python String strip()
Python iter()
Python abs()
Python Decorators
Python List remove()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python int()
Python sum()
Python List
Python Set add()
Python String rindex()
Python String rfind()
Python String splitlines()
Python pass statement
Python callable()
Python Numbers, Type Conversion and Mathematics
Python Tuple
Python Program to Merge Two Dictionaries
Python String lstrip()
Python String endswith()
Python pow()
Python Dictionary get()
Python bool()
Python Program to Print Output Without a Newline
Python oct()
Python String islower()
Python Input, Output and Import
Python Program to Get the Class Name of an Instance
Python float()
Python Set issuperset()
Python Sets