How to delete some element from the set (delete method)
Now, we have seen how can we add some elements to the set.
But if you want to delete some element from the set, how are we going to do that? Well, again we have a method for that. The method that we are going to use is called the delete method. You have guessed it right, that we are going to delete some elements using the delete method now.
Have a look at the below program, where we are trying to make use of the delete method, to delete some elements from the set –
If we have a look at the output now, we can find that element 3 is now deleted from the set, which existed earlier. Have a look at the output –
As you can see, the element that we wanted to delete, is now deleted from the set. This is pretty simple, and you can try out some more examples, to become familiar with the concept of the set, and we can use the method as and when required.