A set is an unordered collection data type with no duplicate elements. Sets are iterable and mutable. The elements appear in an arbitrary order when sets are iterated.
The elements of the set can not be duplicate. The elements of the python set must be immutable.
There are a number of ways to remove items from a set:
Printing the element using for loop... Rakesh Pankaj Anmol Mukesh Sujeet Rahul
In above example, remove() method
is used to remove the element Prayag.
discard() method
Printing the element using for loop... Rahul Anmol Prayag Mukesh Pankaj Sujeet
In above example, discard() method
is used to discard the element Rakesh.
pop() method
Rahul {'Aimtocode', 'Anmol', 'Prayag'}
You can also use the pop()
, method to remove an item, but this method will remove the last item.