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:
Converting Between an Array and a Set in Java
Python Namespace and Scope
Python Set union()
Python Global Keyword
Python getattr()
Python sum()
Python Program to Count the Number of Digits Present In a Number
Python Set add()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Multiply Two Matrices
Python String islower()
Python Program to Find HCF or GCD
Python Input, Output and Import
Python staticmethod()
Python List Comprehension
Python String ljust()
Converting Between a List and a Set in Java
Python Operator Overloading
Python String rindex()
Python Sets
Python Statement, Indentation and Comments
Python Type Conversion and Type Casting
Python filter()
Python Program to Generate a Random Number
Python String encode()
Python print()
Python List extend()
Python Program to Count the Number of Occurrence of a Character in String
Python max()
Python strftime()
Python Closures
Python Program to Find ASCII Value of Character