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 repr()
Python issubclass()
Python String casefold()
Python globals()
Python Program to Shuffle Deck of Cards
Python Tuple index()
Python float()
Python Program to Measure the Elapsed Time in Python
Convert a Map to an Array, List or Set in Java
Building Chatbots with Python Using Natural Language Processing and Machine Learning - Sumit Raj
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Decorators
Python Program to Convert Celsius To Fahrenheit
Python String isspace()
Python Program to Check if a Number is Positive, Negative or 0
Python Closures
Python strptime()
Python Functions
Python Custom Exceptions
Python setattr()
Python Program to Merge Two Dictionaries
Python String format_map()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python ord()
Python Tuple
Python Data Types
Python Recursion
Python Program to Check if a Number is Odd or Even
Python sum()
Python Dictionary update()
Python Set intersection_update()
Python Program to Illustrate Different Set Operations