Python Tutorial Python Advanced Python References Python Libraries

Python Set - clear() Method



The Python 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