The syntax of pop()
for sets is:
set.pop()
pop() Parameters
The pop()
method doesn't take any arguments.
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.
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.