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 Count the Number of Occurrence of a Character in String
Python setattr()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Find the Square Root
Python break and continue
Deep Learning with Python - Francois Cholletf
Python Dictionary get()
Python Set pop()
Python Data Structures and Algorithms - Benjamin Baka
Python String startswith()
Python String maketrans()
Python for Loop
Python Program to Shuffle Deck of Cards
Python String expandtabs()
Python Inheritance
Python Program to Get File Creation and Modification Date
Python String istitle()
Python List sort()
Python Tuple index()
Python Program to Generate a Random Number
Python memoryview()
Python hash()
Python Program to Trim Whitespace From a String
Python issubclass()
Python Program to Concatenate Two Lists
Python Dictionary popitem()
Python Operator Overloading
Python Program to Append to a File
Python Generators
Python sleep()
Python Data Types