Table of Contents
Definition:
This method of a set is used to remove all the elements of the set and returns an empty set. Also, note that this method does not delete the set it only removes the set item.
Syntax:
set.clear()
This method does not take any argument, a passing argument will throw an error.
Working:
Code:
- A set is taken with some values
- We applied clear() method
- Printed the set
Output:
- An empty set is being returned
Interview Questions:
- What is the difference between the clear() method of the list and the clear() method of the set?
They both delete the entire set or list items and returns an empty list or set, so technically there is no difference.