Table of Contents
The clear() method removes all elements from the set.
The syntax of clear() method is:
set.clear()
1. Set clear() Parameters
clear() method doesn’t take any parameters.
2. Return value from Set clear()
clear() method doesn’t return any value and returns a None.
3. 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
vowels.clear()
print('Vowels (after clear):', vowels)
Output
Vowels (before clear): {'e', 'a', 'o', 'u', 'i'}
Vowels (after clear): set()
Related posts:
Python frozenset()
Python Strings
Python Dictionary clear()
Python String isspace()
Python String isdigit()
Python super()
Python String lower()
Python Dictionary items()
Python Program to Shuffle Deck of Cards
Python Program to Check Whether a String is Palindrome or Not
Python next()
Python Set add()
Python Operators
Python Statement, Indentation and Comments
Python Anonymous / Lambda Function
Python String expandtabs()
Python sorted()
Python String lstrip()
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Global, Local and Nonlocal variables
Python Program to Iterate Over Dictionaries Using for Loop
Python Iterators
Python Program to Iterate Through Two Lists in Parallel
Python Decorators
Python Shallow Copy and Deep Copy
Python Program to Swap Two Variables
Python any()
Python Set pop()
Python Dictionary fromkeys()
Python Objects and Classes
Python Set intersection()
Python Program to Generate a Random Number