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 List extend()
Python Numbers, Type Conversion and Mathematics
Python String strip()
Python enumerate()
How to get current date and time in Python?
Python String title()
Python Program Read a File Line by Line Into a List
Python __import__()
Python List remove()
Python String format()
Python Program to Print Hello world!
Python Program to Add Two Numbers
Python String isdigit()
Machine Learning with Python for everyone - Mark E.Fenner
Python Set copy()
Python List insert()
Python object()
Python Program to Print Colored Text to the Terminal
Python Dictionary get()
Python range()
Python compile()
Python Tuple index()
Python Directory and Files Management
Python Set issubset()
Python Sets
Python Objects and Classes
Python Program to Swap Two Variables
Python Global, Local and Nonlocal variables
Python Program to Check if a Key is Already Present in a Dictionary
Python Set remove()
Python Program to Find the Size (Resolution) of a Image
Python map()