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 setattr()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python frozenset()
Python callable()
Python String translate()
Python enumerate()
Python @property decorator
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Program to Multiply Two Matrices
Python String zfill()
Python Program to Find Armstrong Number in an Interval
Python Program to Transpose a Matrix
Deep Learning with Python - Francois Chollet
Introduction to Scientific Programming with Python - Joakim Sundnes
Python hash()
Python Set pop()
Python hex()
Python Matrices and NumPy Arrays
Python object()
Python Program to Print Hello world!
Python Program to Print the Fibonacci sequence
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python List copy()
Python Set union()
Python bin()
Python pow()
Python max()
Python Operators
Python strptime()
Python Program to Add Two Matrices
Python Program to Compute all the Permutation of the String
Python Program to Append to a File