Python Set clear() Method

Example

Remove all elements from the fruits set:

fruits = {"apple", "banana", "cherry"}
fruits.clear()
print(fruits)

Run Example

Definition and Usage

The clear() method removes all elements from the set.

Syntax

set.clear()

Parameter Value

No parameters.