Google News
logo
Python Program to Remove the last item in a set by using the pop() method
The `pop()` method in a set removes and returns an arbitrary element from the set.

There is no concept of the "last" element in a set, since the elements are not ordered.

However, here's an example program that demonstrates how to use the `pop()` method to remove an element from a set :
Program :
# create a set
my_set = {"apple", "banana", "cherry"}

# remove and return an arbitrary element
removed_element = my_set.pop()

print("Removed element:", removed_element)
print("Updated set:", my_set)
Output :
Removed element: banana
Updated set: {'cherry', 'apple'}