English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The clear() method removes all items from the list.
The syntax of the clear() method is:
list.clear()
The clear() method does not take any parameters.
The clear() method only clears the givenlist. It does not return any value.
# Define a list list = [{1, 2}, ('a'), ['1.1', ''2.2']] # Clear the list list.clear() print('List:', list)
When running the program, the output is:
List: []
Note:If you are using Python 2or Python 3.2and lower versions, the clear() method cannot be used. You can use the del operator instead.
# Define a list list = [{1, 2}, ('a'), ['1.1', ''2.2']] # Clear the list del list[:] print('List:', list)