Python Set clear()

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

The syntax of clear() method is:


Set clear() Parameters

The clear() method doesn't take any parameters.

Return value from Set clear()

The clear() method doesn't return any value and returns a 'None'.

Example 1: Remove all elements from a Python set using clear()

# set of vowels
vowels = {'a', 'e', 'i', 'o', 'u'}
print('Vowels (before clear):', vowels)

# clearing vowels
print('Vowels (after clear):', vowels)

When you run the program, the output will be:

Vowels (before clear): {'e', 'a', 'o', 'u', 'i'}
Vowels (after clear): set()