

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
set clear() in python
In this tutorial, we are going to learn about the clear method of set data structure. Let's see details about the clear method.
The method clear is used to clear all the data from the set data structure. All elements from set will clear. And we will leave with an empty set.
Follow the below steps to see clear method in action.
- Initialize a set.
- User the clear method and clear the set.
- Print the set and you will see an empty one.
Example
# initialzing a set number_set = {1, 2, 3, 4, 5} # clearing the set number_set.clear() # printing the set print(number_set)
Output
If you run the above code, then you will get the following result.
set()
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.
- Related Questions & Answers
- Python Program to Clear the Rightmost Set Bit of a Number
- How to clear screen in python?
- How to clear Python shell?
- Clear/Set a specific bit of a number in Arduino
- How to clear screen using python?
- Different ways to clear a list in Python
- How do you set, clear, and toggle a bit in C/C++?
- Clear LinkedList in Java
- Clear element.classList in JavaScript?
- Java ConcurrentHashMap - clear()
- How do I clear the regular expression cache in Python?
- How to clear the text entered in Selenium with python?
- Clear a StringBuilder in C#
- Clear a list in C#
- LinkedList Clear() Method in C#
Advertisements