Menu Close

Python Set clear() Method

Python set clear method

Here we are going to learn all about Python set clear() method along with an example. clear function in python is used to remove all items from the set.

In the previous tutorial, we have seen all about the python set along with some examples.
I recommend, before going through this tutorial, please check out our previous python set tutorial.

Python Set clear() Method

In Python, clear function in python is a set built-in function which only used with sets. clear function in python is used to remove all the items from the set.

Syntax

The syntax of the python set clear method is:-

set.clear()

Parameter

clear function in python does not accepts any parameter.

Python set clear() exmaple

Here we will use clear function in Python to remove all items from the set.

Example:

my_set = { 1, 2, 3, 4, 5, 6, 7 }
print(my_set)
my_set.clear()
print(my_set)

Output

{1, 2, 3, 4, 5, 6, 7}
set()

Conclusion

In this tutorial, you have learned all about the clear function in python to remove all items from the set.

I hope this article will help you. If you like this article, please share it with your friends who want to learn Python programming from scratch.

For More Information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts

Leave a Reply