Skip to main content

clear()

The clear() method in Python is a list method that removes all the elements from a list. It modifies the original list in place by making it empty.

Parameter Values

This function does not accept any parameters.

Return Values

The clear() method from List Methods returns None.

How to Use clear() in Python

Example 1:

The clear() method removes all elements from a list.

lst = [1, 2, 3, 4, 5]
lst.clear()
print(lst) # Output: []
Example 2:

It modifies the original list in place and returns None.

numbers = [10, 20, 30, 40, 50]
numbers.clear()
print(numbers) # Output: []
Example 3:

Using clear() on an empty list will result in an empty list.

empty_list = []
empty_list.clear()
print(empty_list) # Output: []