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 Set remove()
Python String encode()
Python String format()
Python all()
Python String istitle()
Python Dictionary get()
Python String upper()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python if...else Statement
Python String rindex()
Python Program to Concatenate Two Lists
Python Set update()
Python Program to Create Pyramid Patterns
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Get the File Name From the File Path
Python String count()
Python Program to Find ASCII Value of Character
Python break and continue
Python String rjust()
Python Program to Count the Number of Occurrence of a Character in String
Python Iterators
Python type()
Python sum()
Python Set discard()
Python String startswith()
Converting Between an Array and a Set in Java
Python dir()
Python Dictionary
Python for Loop
Python Package
Python Tuple count()
Python Program to Reverse a Number