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 Multiple Inheritance
Python Program to Solve Quadratic Equation
Python abs()
Python Data Structures and Algorithms - Benjamin Baka
Python Object Oriented Programming
Python Program to Make a Simple Calculator
Python String istitle()
Python Global, Local and Nonlocal variables
Python repr()
Python Variables, Constants and Literals
Python String title()
Python Program to Calculate the Area of a Triangle
Python frozenset()
Python String strip()
Deep Learning with Python - Francois Cholletf
Python String partition()
Python Program to Access Index of a List Using for Loop
Python Program to Compute the Power of a Number
Python iter()
Python open()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python Set copy()
Python Set remove()
Python any()
Python Program to Get the Class Name of an Instance
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Display Fibonacci Sequence Using Recursion
Python Operator Overloading
Python String encode()
Python Program to Get the Full Path of the Current Working Directory
Python String maketrans()
Python sleep()