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 int()
Python Program to Measure the Elapsed Time in Python
Python String title()
Python String translate()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python filter()
Python Dictionary fromkeys()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python help()
Python map()
Python Program to Count the Number of Digits Present In a Number
Python Program to Calculate the Area of a Triangle
Python range()
Python dir()
Python @property decorator
Python Program to Print the Fibonacci sequence
Python Program to Find LCM
Python datetime
Python String isalpha()
Python Operators
Python Program to Find ASCII Value of Character
Python Multiple Inheritance
Python List pop()
Python Program to Find the Factorial of a Number
Python String rpartition()
Python tuple()
Python String ljust()
Python Program to Check if a Number is Positive, Negative or 0
Python Program to Shuffle Deck of Cards
Python String isdigit()
Python String islower()
Python Program to Append to a File