Python Set clear()

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

The syntax of clear() method is:


Set clear() Parameters

clear() method doesn't take any parameters.

Return value from Set clear()

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)


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