Python Set - clear method

The clear method removes all the members from the set and makes the set an empty set.

Set Updated 16 Sep 2016 1 min read

Method signature

clear()

Method Overview

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

Example

python
# 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

Output
set()

0