How To Remove Elements From a Set using pop() function in python

34

"""
We can use the pop() function to remove the last item in a set,
but because a set is unordered, we will not know what item will be removed.
The pop() function will return the element that was removed
"""

mySet = {1, 2, 3}
removedElement = mySet.pop()
print(removedElement)
print(mySet)

"""
Output:
1
{2, 3}
"""

Comments

Submit
0 Comments