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 List sort()
Python Program to Parse a String to a Float or Int
Python List count()
Python time Module
Python Modules
Python Program to Get a Substring of a String
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python str()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python sleep()
Java Program to Implement Dijkstra’s Algorithm using Set
Python Set intersection_update()
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python List clear()
Python Decorators
Python complex()
Python Set discard()
Python Shallow Copy and Deep Copy
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program Read a File Line by Line Into a List
Python String isdigit()
Python Function Arguments
Python Namespace and Scope
Python Program to Measure the Elapsed Time in Python
Python Program to Display Calendar
Python Functions
Python Program to Check If Two Strings are Anagram
Python Operator Overloading
Python Program to Return Multiple Values From a Function
Python Set symmetric_difference()
Python List copy()