This program demonstrates how to clear or remove all elements from a set in Python. The code first declares a set color containing various colors as strings. The set is then printed to show its original values and the type of the set. Next, the clear() method is used to remove all elements from the set color. The set is then printed again to show that it's now an empty set. In this example, the clear() method removes all elements from the set color, and the set is now empty. The type of the set remains unchanged, which is set.
color = {"Red","Green","Pink","White","Black","Yellow","Blue"} print(color) print(type(color)) #Remove All Elements from given set color.clear() print("\nAfter Remove all Elements give Sets :",color) print(type(color))
{'Red', 'Green', 'Black', 'Pink', 'White', 'Yellow', 'Blue'} <class 'set'> After Remove all Elements give Sets : set() <class 'set'>
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions