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:
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Python Program to Catch Multiple Exceptions in One Line
Python Program to Convert Kilometers to Miles
Python String rindex()
Python Deeper Insights into Machine Learning - Sebastian Raschka & David Julian & John Hearty
Python Program to Append to a File
Node.js vs Python for Backend Development
Python Set copy()
Python slice()
Python len()
Python String isalnum()
Python Recursion
Python str()
Python sorted()
Python Strings
Python String casefold()
Python String zfill()
Python datetime
Python Set issubset()
Python float()
Converting Between a List and a Set in Java
Python Functions
Python Matrices and NumPy Arrays
Python Dictionary pop()
Python max()
Python Program to Display Calendar
Python Shallow Copy and Deep Copy
Python Set difference()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python open()
Python Global, Local and Nonlocal variables
Python Set symmetric_difference()