Home »
Python
Python Set clear() Method with Example
Python Set clear() Method: Here, we are going to learn how to clear/remove all elements of the set in Python?
Submitted by IncludeHelp, on November 27, 2019
Set clear() Method
clear() method is used to clear/remove all elements of the set.
Syntax:
set_name.clear()
Parameter(s):
- It does not accept any parameter.
Return value:
The return type of this method is None.
Example:
# Python Set clear() Method with Example
# declaring a set
cities = {"New Delhi", "Mumbai", "Indore", "Gwalior"}
# printing set before clearing the element
print("cities = ", cities)
# clearing all elements
cities.clear()
# printing set after clearing the element
print("cities = ", cities)
Output
cities = {'Indore', 'Gwalior', 'New Delhi', 'Mumbai'}
cities = set()
ADVERTISEMENT
ADVERTISEMENT