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:
How to Get Started With Python?
Python break and continue
Python Dictionary clear()
Python Functions
APIs in Node.js vs Python - A Comparison
Node.js vs Python for Backend Development
Python Get Current time
Python String center()
Python Set remove()
Python Program to Solve Quadratic Equation
Python Program to Display the multiplication Table
Python Function Arguments
Python Program to Find the Largest Among Three Numbers
Python repr()
Python staticmethod()
Python globals()
Python memoryview()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Find ASCII Value of Character
Python Strings
Python String title()
Python Generators
Python round()
Python Program to Display Fibonacci Sequence Using Recursion
Python Dictionary
Python Program to Convert Two Lists Into a Dictionary
Python Program to Trim Whitespace From a String
Python Program to Check if a Number is Positive, Negative or 0
Python int()
Python Errors and Built-in Exceptions
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Split a List Into Evenly Sized Chunks