clear() of Sets in Python
clear() of Sets in Python
The clear() method removes all the elements present in a set. Basically it is used to clear the set. The clear() method is handy when you need to reset a set or remove all its elements to start with a clean slate.
clear() method does not take any parameters.
clear() of Sets in Python
In Python, the clear() method is used with sets to remove all elements from the set, leaving it empty. It essentially empties the contents of the set, making it a set with no elements.
Syntax :
Return Type :
The clear() method does not return any value.
#clear() in python set set1 = {'P', 'Y', 'T', 'H', 'O', 'N' } print(set1) #all the values deleted from set set1.clear() print(set1)
Output : {'T', 'O', 'H', 'N', 'P', 'Y'} set()
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment