Python Tutorial Python Advanced Python Resources Python Libraries
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Python - Set clear() Method



The Python set clear() method is used to delete all elements of the set.

Syntax

set.clear()

Parameters

No parameter is required.

Return Value

None.

Example:

In the example below, the clear() method is used on set called MySet to delete all elements of the set.

MySet = {10, 50, 50, 100, 1000, 1000}
#delete all elements from the set.
MySet.clear()      
print(MySet)

The output of the above code will be:

set()

❮ Python Set Methods

5