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 timestamp to datetime and vice-versa
Python String isspace()
Python Machine Learning - Sebastian Raschka
Python Program to Calculate the Area of a Triangle
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Swap Two Variables
Python Program to Append to a File
Python List
Python any()
Python String find()
APIs in Node.js vs Python - A Comparison
Deep Learning with Python - Francois Cholletf
Python Decorators
Python List extend()
Python Program Read a File Line by Line Into a List
Python Tuple index()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Directory and Files Management
Python Program to Sort a Dictionary by Value
Python next()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String islower()
Python set()
Python List append()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python super()
Python Program to Check Leap Year
Python Data Types
Python Program to Catch Multiple Exceptions in One Line
Python String index()
Python String maketrans()
Python Program to Check If a String Is a Number (Float)