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 Multiply Two Matrices
Python String rfind()
Python while Loop
Python List
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Operators
Python Operator Overloading
Python Set copy()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python bin()
Python File I/O Operation
Python Program to Display Calendar
Python String title()
Python Objects and Classes
Python Set issubset()
Python Program to Make a Flattened List from Nested List
Python sleep()
Python Multiple Inheritance
Python Inheritance
Python Program to Extract Extension From the File Name
Python RegEx
Python String encode()
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Find the Factors of a Number
Python Program to Randomly Select an Element From the List
Python String capitalize()
Python any()
APIs in Node.js vs Python - A Comparison
Python Program to Parse a String to a Float or Int
Python Program to Slice Lists