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 min()
Python Inheritance
Python repr()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Deep Learning Cookbook - Indra den Bakker
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Convert Kilometers to Miles
Python hash()
Python Global, Local and Nonlocal variables
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Convert Bytes to a String
Python frozenset()
Python String lower()
Python Custom Exceptions
Python Dictionary clear()
Python List pop()
Python String split()
Python String isnumeric()
Python Program to Find Sum of Natural Numbers Using Recursion
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Python filter()
Python Object Oriented Programming
Python dict()
Python Program to Get File Creation and Modification Date
Python Objects and Classes
Python strptime()
Python help()
Python Sets
Python time Module
Python Dictionary fromkeys()
Python int()