Python List clear() Method28 Jun 2025 | 3 min read The Python list clear() method removes all the elements from the list. It clear the list completely and returns nothing. It does not require any parameter and returns no exception if the list is already empty. Syntax of the clear() Method in Python ListThe following is the syntax of the list clear() method: Syntax: Parameter:
Return:
Examples of List clear()Let's see some examples of list clear() method to understand it's functionality. Example 1: Simple Use of the List clear() MethodLet's see a simple example in which clear() method is used to clear a list. The clear() method clears all the elements from the list. ExampleExecute NowOutput: Given List: ['1', '2', '3'] Updated List: [] Explanation: In the above example, we are given a list. We used the clear() method to remove all the elements from the list. As a result, the list becomes empty. Example 2: Clearing an Empty ListIf the list is already empty, the method returns nothing. See the example below. ExampleExecute NowOutput: Given List: [] Updated List: [] Explanation: In this example, we are given an empty list. We used the clear() method to clear the list. Since, the list is already empty, there is no impact on the list after using clear(). Hence, it returns nothing. ConclusionPython contains different built-in methods and functions that help developers to easily create flawless software. The Python list clear() method is extremely useful in situations where we want to quickly empty the list. This tutorial has covered all the details and examples regarding this method, but don't limit yourself to these examples; instead, try more and more examples to be proficient. Python List clear() Method FAQs1) What is the purpose to use clear() method in Python? Demonstrate this using an example The clear() method is used to remove all the elements from the list.. The syntax of the clear() is as follows: Syntax: ExampleExecute NowOutput: Original List: ['1', '2', '3'] List after Clearing the elements: [] 2) What does the clear() method returns? The clear() method returns none. It only removes all the elements from the existing list. 3) What will happen if we apply clear() method on an empty list? If we apply clear() method on an empty list, nothing happens. The original list is empty or it will remain empty. 4) Does clear() delete the list itself? No, clear() removes the elements inside the list, but the list object still exists. 5) Can clear() be used on other data types like strings or tuples? No, clear() is only available for lists, dictionaries, sets, etc. Immutable types like strings and tuples don't support it. Next TopicPython list count method |
We request you to subscribe our newsletter for upcoming updates.