Easy Tutorial
❮ Python File Close Python Att Dictionary Clear ❯

Python Set clear() Method

Python Set


Description

The clear() method is used to remove all elements from the set.

Syntax

Syntax of the clear() method:

set.clear()

Parameters

Return Value

None.

Example

Remove all elements from the fruits set:

Example 1

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

Output:

set()

Python Set

❮ Python File Close Python Att Dictionary Clear ❯