Free cookie consent management tool by TermsFeed Python Set - clear method | Pythontic.com

Python Set - clear method

Method signature:

clear()

Method Overview:

Removes all elements from the set, which makes the set an empty set.

Example:

# Example Python program that removes all the elements of a set 

# Create a set with five elements
box = {"Pencil", "Eraser", "Pen", "Highlighter", "Paper clip"}

# Remove all the elememts
box.clear()

# Print the set contents
print(box)
print(len(box))

Output:

set()

0

 


Copyright 2025 © pythontic.com