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 String islower()
Python Program to Find the Factorial of a Number
Python Program to Convert Celsius To Fahrenheit
Python print()
Python filter()
Python Program to Differentiate Between type() and isinstance()
Python dict()
Python exec()
Python String upper()
Python Program to Slice Lists
Python Program to Make a Flattened List from Nested List
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python strftime()
Python min()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Machine Learning - Sebastian Raschka
Python Program to Convert Bytes to a String
Python String rfind()
Python sleep()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Extract Extension From the File Name
Python Program to Find the Largest Among Three Numbers
Python Program to Print Hello world!
Python if...else Statement
Python issubclass()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Dictionary setdefault()
How to get current date and time in Python?
Python Set clear()
Python RegEx
Python String capitalize()