The clear() function in python helps to remove all the elements from the list. After this method calling the list gets initialized to an empty object.
list.clear() #where list in which needs to clear
The clear() method doesn't take any parameters. We can say that this method is equivalent to del a[:].
This method doesn't return any value. It just makes the list empty.
# Defining a list
org_list = [{5, 6}, ('x'), ['5.5', '6.6']]
# clearing the list
org_list.clear()
print('List after clear:', org_list)
Output:
List after clear: []
Note: We can use the del operator instead of clear(),in case of using Python 2 or Python 3.2 and below
# Defining a list
org_list = [{5, 6}, ('x'), ['5.5', '6.6']]
# clearing the list
del org_list[:]
print('List after delete:', org_list)
Output:
List after delete: []