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 center()
Python Program to Find the Factorial of a Number
Python String isdigit()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Check the File Size
Python Object Oriented Programming
Python File I/O Operation
Python ascii()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Strings
Python Program to Convert Two Lists Into a Dictionary
Python delattr()
Python String islower()
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python open()
Python String title()
Python String isprintable()
Python Data Structures and Algorithms - Benjamin Baka
Python String zfill()
Python len()
Python Multiple Inheritance
Python Directory and Files Management
Python Program to Concatenate Two Lists
Python Dictionary
Python Program to Print the Fibonacci sequence
Python strftime()
Python Program to Multiply Two Matrices
Python Program to Find Hash of File
Python int()
Python Program to Convert Bytes to a String
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python format()