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 Find Sum of Natural Numbers Using Recursion
Python getattr()
Python Program to Create Pyramid Patterns
Python print()
Python map()
Python Program to Return Multiple Values From a Function
Python isinstance()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Dictionary copy()
Python List pop()
Converting Between an Array and a Set in Java
Python Program to Transpose a Matrix
Python String endswith()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python len()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Variables, Constants and Literals
Python Program to Convert Kilometers to Miles
Python Objects and Classes
Python List clear()
Deep Learning in Python - LazyProgrammer
Python Program to Represent enum
Introduction to Scientific Programming with Python - Joakim Sundnes
Python open()
Python Program to Delete an Element From a Dictionary
Python Program to Find Hash of File
Python Sets
Python ascii()
Python List
Python delattr()
Python dict()
Python String swapcase()