Python - Set clear() Method


Advertisements

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

Syntax


set.clear()

Parameters

No parameter is required.

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)

Output

set()

Sets Methods




Advertisements