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 Statement, Indentation and Comments
Python bin()
Python delattr()
Python round()
Python Program to Get File Creation and Modification Date
How to Get Started With Python?
Python help()
Python Program to Find HCF or GCD
Python Program to Find ASCII Value of Character
Python max()
Python Program to Convert Celsius To Fahrenheit
Python Program to Shuffle Deck of Cards
Python classmethod()
Python oct()
Python format()
Python List index()
Python Program to Calculate the Area of a Triangle
Python String rjust()
Python input()
Python Program to Find Armstrong Number in an Interval
Python String endswith()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Find the Square Root
Python Program to Find Factorial of Number Using Recursion
Python Machine Learning - Sebastian Raschka
Python Set isdisjoint()
Python complex()
Python Program to Check Whether a String is Palindrome or Not
Python String split()
Python String rfind()
Python compile()
Python filter()