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 compile()
Python Program to Get the File Name From the File Path
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Print Hello world!
Python Type Conversion and Type Casting
Python Program to Get File Creation and Modification Date
Python hasattr()
Python Set clear()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python eval()
Python hash()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python String format()
Python Set intersection()
Python bool()
Python setattr()
Python Program to Check If Two Strings are Anagram
Python Program to Remove Punctuations From a String
Converting Between an Array and a Set in Java
Python frozenset()
Python Program Read a File Line by Line Into a List
Python Program to Merge Two Dictionaries
Python List Comprehension
Python Set issubset()
Python Program to Calculate the Area of a Triangle
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Iterate Through Two Lists in Parallel
Python for Loop
Python iter()
Python File I/O Operation
Python String isalnum()
Python RegEx