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 Get Current time
Python Program to Generate a Random Number
Python Dictionary get()
Python String isprintable()
Python Program to Check the File Size
Python Matrices and NumPy Arrays
Python dict()
Python Namespace and Scope
Python String isupper()
Python Program to Find Armstrong Number in an Interval
Python float()
Python while Loop
Python Program to Get the Last Element of the List
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python datetime
Python format()
Python chr()
Python Program to Iterate Over Dictionaries Using for Loop
Java Program to Implement Dijkstra’s Algorithm using Set
Python Program to Check If Two Strings are Anagram
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python pass statement
Python List reverse()
Python Program to Get a Substring of a String
Python Program to Transpose a Matrix
Python String casefold()
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Append to a File
Python issubclass()
Python Set difference()
Python vars()
Python Program to Count the Number of Digits Present In a Number