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 Data Types
Python Program to Make a Flattened List from Nested List
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Deep Learning with Python - Francois Chollet
Python Program to Merge Two Dictionaries
Python Get Current time
Python sum()
Python Decorators
Deep Learning in Python - LazyProgrammer
Python format()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Trim Whitespace From a String
Python Program to Reverse a Number
Python Program to Count the Number of Occurrence of a Character in String
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Measure the Elapsed Time in Python
Python Program to Shuffle Deck of Cards
Python Recursion
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Data Structures and Algorithms - Benjamin Baka
Python List sort()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Converting Between an Array and a Set in Java
Python Program to Print Hello world!
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python @property decorator
Python Program to Compute all the Permutation of the String
Python Program to Parse a String to a Float or Int
Python String isspace()
Python Namespace and Scope
Python iter()
Python String isprintable()