Python List clear() Method
The Python List clear() method is used for removing all items from the List.
Syntax: list.clear()
Parameters:
The clear() method doesn’t take any parameters
Returns:
The method doesn’t return any value
Example 1: Using clear() method in List
Python3
# Python program to clear a list# using clear() method # Creating listGEEK = [6, 0, 4, 1]print('GEEK before clear:', GEEK) # Clearing listGEEK.clear()print('GEEK after clear:', GEEK) |
Output:
GEEK before clear: [6, 0, 4, 1] GEEK after clear: []
Example 2:
Python3
# Defining a listlist = [{1, 2, 3, 4}, ['1.1', '2.2']] # clearing the listlist.clear() print(list) |
Output:
[]



