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 Program to Find the Largest Among Three Numbers
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Display Fibonacci Sequence Using Recursion
Python int()
Python Dictionary keys()
Python List
Python divmod()
Python sum()
Python Program to Print Hello world!
Python String isidentifier()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python ascii()
Python Program to Merge Mails
Python Set symmetric_difference()
Python Program to Check the File Size
Python Program to Check if a Key is Already Present in a Dictionary
Python Program to Compute the Power of a Number
Python Set union()
Python Program to Get the Full Path of the Current Working Directory
Python String endswith()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Dictionary pop()
Python String partition()
Python Program to Find ASCII Value of Character
Python super()
Deep Learning with Python - Francois Chollet
Intelligent Projects Using Python - Santanu Pattanayak
Python List extend()
Python Program to Check Prime Number
Python Operators
Python String lower()