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 Program to Find HCF or GCD
Python memoryview()
Python eval()
Python Program to Convert Bytes to a String
Python Program to Differentiate Between type() and isinstance()
Python String isalpha()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Get Line Count of a File
Python Program to Measure the Elapsed Time in Python
Python Program to Return Multiple Values From a Function
Python Matrices and NumPy Arrays
Python Program to Capitalize the First Character of a String
Python Shallow Copy and Deep Copy
APIs in Node.js vs Python - A Comparison
Python if...else Statement
Python enumerate()
Python String isdecimal()
Python Set difference_update()
Python String format_map()
Python Custom Exceptions
Python Statement, Indentation and Comments
Python Function Arguments
Python Dictionary get()
Convert a Map to an Array, List or Set in Java
Python zip()
Python String lower()
Python oct()
Python Program to Get the Class Name of an Instance
Python frozenset()
Python filter()
Python Program to Make a Flattened List from Nested List
Python strftime()