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:
APIs in Node.js vs Python - A Comparison
JavaScript Map and Set
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python String count()
Python Program to Slice Lists
Python Program to Remove Punctuations From a String
Python Program to Count the Occurrence of an Item in a List
Python Program to Check the File Size
Python isinstance()
Python String endswith()
Python String find()
Python List append()
Python Set isdisjoint()
Python Program to Find HCF or GCD
Python Program to Display the multiplication Table
Python Program to Find Numbers Divisible by Another Number
Python Program to Check Armstrong Number
Python ascii()
Python eval()
Python Program to Append to a File
Python String index()
Python issubclass()
Python List pop()
Python Program to Check Leap Year
Python String format()
Python String rjust()
Python compile()
Python Program to Multiply Two Matrices
Python Sets
Python List remove()
Python Program to Find Armstrong Number in an Interval
Python for Loop