Python Set clear
Now, we are going to have a look at the clear method. As the name of the method says, with the clear method, all the elements are removed from the set. The clear method does not take any arguments, and also, it returns None.
Let’s have a look at a simple program, which demonstrates the use of the clear method –
Python Set clear Method
As you can see, in the above program, we are having a simple set, and then we are trying to make use of the clear method. With the clear method, all the elements from the set are removed, and then we have an empty set. In the last instruction, we are printing the set. If you execute the above program and observe the output, you can find that we get set() as output, which is nothing but an empty set.
So, as and when required, we can make use of the clear method in our python programs.