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 property()
Python Program to Count the Occurrence of an Item in a List
Python Program to Access Index of a List Using for Loop
Python eval()
Python Type Conversion and Type Casting
Python String title()
Python Program to Check if a Number is Positive, Negative or 0
Python Functions
Python Deep Learning Cookbook - Indra den Bakker
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Python oct()
Python Tuple index()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python dir()
Python chr()
Python round()
Python Set difference_update()
Python Generators
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Dictionary keys()
Python del Statement
Python Tuple
Python Program to Remove Duplicate Element From a List
Python String maketrans()
Python iter()
Python help()
Java Program to Implement Dijkstra’s Algorithm using Set
Python Program to Make a Flattened List from Nested List
Python Dictionary clear()
Python staticmethod()
Python Machine Learning - Sebastian Raschka
Python Inheritance