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:
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python String index()
Python Program to Find Factorial of Number Using Recursion
Python String upper()
Python delattr()
Python Data Structures and Algorithms - Benjamin Baka
Python Program to Randomly Select an Element From the List
Python property()
Python Namespace and Scope
Python Program to Find the Size (Resolution) of a Image
Python Program to Compute the Power of a Number
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python all()
Python Object Oriented Programming
Node.js vs Python for Backend Development
Python input()
Python Function Arguments
Python List sort()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Tuple count()
Python List count()
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Python for Loop
Python Machine Learning - Sebastian Raschka
Python String translate()
Python Program to Iterate Over Dictionaries Using for Loop
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python String lstrip()
Python Program to Find the Factorial of a Number
Python Program to Find the Factors of a Number
Python list()
Deep Learning with Python - Francois Cholletf