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 issubclass()
Python List Comprehension
Python Operator Overloading
Python Generators
Python String rstrip()
Python Program to Catch Multiple Exceptions in One Line
Python String replace()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Get the Last Element of the List
Python strftime()
Python String find()
Python Set update()
Python type()
Python Program to Check If a List is Empty
Python String casefold()
Python File I/O Operation
Python String index()
Python Program to Parse a String to a Float or Int
Python object()
Python Program to Find the Factors of a Number
Python Set difference_update()
Python String ljust()
Python super()
Python String isidentifier()
Python String splitlines()
Python open()
Python Program to Check Whether a String is Palindrome or Not
Introduction to Scientific Programming with Python - Joakim Sundnes
Python List extend()
Python Program to Transpose a Matrix
Python Keywords and Identifiers
Python round()