Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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 below example, 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