Python Set clear() Method Tutorial

In this section, we will learn what the Set clear() method is and how to use it in Python.

What is Set clear() Method in Python?

The Python Set clear() method is used to remove the entire elements of a Set object.

Python Set clear() Method Syntax:

set.clear()

Set clear() Method Parameter:

The method does not take an argument.

Set clear() method Return Value

The method does not return a value.

Example: using python set clear() method

set1 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}

print(len(set1))

set1.clear()

print(len(set1))

Output:

15

0
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies