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 Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Find the Factorial of a Number
Python Program to Find Hash of File
Python Program to Swap Two Variables
Python globals()
Python help()
Python Program to Reverse a Number
Python iter()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python List count()
Python hasattr()
Python Program to Remove Duplicate Element From a List
Python String find()
Python vars()
Python Program to Make a Flattened List from Nested List
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python List
Python Program to Compute the Power of a Number
Python enumerate()
Python Tuple index()
Python Program to Find the Size (Resolution) of a Image
Python Set symmetric_difference_update()
Python String capitalize()
Python Program to Get a Substring of a String
Python Program to Display the multiplication Table
Python Program to Sort Words in Alphabetic Order
Python filter()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python dir()
Python Program to Get the File Name From the File Path
Python Program to Check Leap Year