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 Program to Generate a Random Number
Python Program to Slice Lists
Python String partition()
Python Decorators
Python print()
Python List append()
Python __import__()
Python hasattr()
Python String join()
Python Program to Capitalize the First Character of a String
Python Data Structures and Algorithms - Benjamin Baka
Java Program to Implement Dijkstra’s Algorithm using Set
Python Dictionary copy()
Python Program to Find ASCII Value of Character
Python timestamp to datetime and vice-versa
Python hex()
Python String maketrans()
Python Program to Check if a Number is Positive, Negative or 0
Python String zfill()
Python Matrices and NumPy Arrays
Python List insert()
Python *args and **kwargs
Python dict()
Python Program to Measure the Elapsed Time in Python
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python Program to Check Armstrong Number
Python staticmethod()
Python Program to Remove Punctuations From a String
Python Program to Differentiate Between del, remove, and pop on a List
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python str()
Python list()