Home >>Python Set Methods >Python Set clear() Method

Python Set clear() Method

Python Set clear() Method

Python set clear() method is used to remove all the elements in the given input set.

Syntax:
set.clear()
Here is an example of Python clear() method:

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

Output:
set()
Example 2

newset = {"php","python","java"}
thisset.clear()
print(thisset)

Output:
set()

No Sidebar ads