The set
type represents a collection of unordered, unique elements. Set objects are mutable in that they can be modified after creation by adding or removing elements.
The pop()
methods is used to remove and return an arbitrary element from the set.
myset.pop()
The pop()
method does not take any argument, it returns the removed element. A KeyError
exception is raised if the set is empty.
The following shows an example with an empty set.
pop() vs remove()
While the pop()
method removes an arbitrary element, the remove()
method removes the element specified as an argument from the set. It also raises a KeyError
if the element is not present.