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 if...else Statement
Python Set difference()
Python Set issubset()
Python vars()
Python String maketrans()
Python while Loop
Python Variables, Constants and Literals
Python Program to Check Prime Number
Python List
Python format()
Python List Comprehension
Python String isprintable()
Python Program to Get the Full Path of the Current Working Directory
Python Program to Count the Number of Each Vowel
Python Dictionary items()
Python Keywords and Identifiers
Python String partition()
Python getattr()
Python Program to Get a Substring of a String
Python Objects and Classes
Convert a Map to an Array, List or Set in Java
Python List extend()
Python Object Oriented Programming
Python slice()
Python Program to Get Line Count of a File
Python Dictionary update()
Python Program to Check if a Number is Odd or Even
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Convert Decimal to Binary Using Recursion
Python String rpartition()
Python strptime()
Python Program to Check Armstrong Number