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 staticmethod()
Python List sort()
Python String endswith()
Python eval()
Python print()
Python Program to Merge Two Dictionaries
Python datetime
Python String index()
Python Program to Check If a List is Empty
Python Set update()
Python next()
Python Program to Print Colored Text to the Terminal
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Dictionary pop()
Python Program to Parse a String to a Float or Int
Python Program to Create a Long Multiline String
Python locals()
Python getattr()
Python Program to Merge Mails
Python Program to Create Pyramid Patterns
Python Set issuperset()
Python zip()
Python String title()
Python Program to Make a Simple Calculator
Python Variables, Constants and Literals
Python frozenset()
Python type()
Python Numbers, Type Conversion and Mathematics
Python Program to Concatenate Two Lists
Python String rjust()
Python String isupper()
Python int()