The clear() method removes all items from the list.
The syntax of clear() method is:
list.clear()
The clear() method doesn’t take any parameters.
The clear() method only empties the given list. It doesn’t return any value.
# Defining a list
list = [{1, 2}, ('a'), ['1.1', '2.2']]
# clearing the list
list.clear()
print('List:', list)
When you run the program, the output will be:
List: []
Note: If you are using Python 2 or Python 3.2 and below, you cannot use the clear() method. You can use the del operator instead.
# Defining a list
list = [{1, 2}, ('a'), ['1.1', '2.2']]
# clearing the list
del list[:]
print('List:', list)
#python