Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python List clear() Method

  • Last Updated : 04 Aug, 2021

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 list
GEEK = [6, 0, 4, 1]
print('GEEK before clear:', GEEK)
  
# Clearing list
GEEK.clear()
print('GEEK after clear:', GEEK)

Output:

GEEK before clear: [6, 0, 4, 1]
GEEK after clear: []

Example 2: 

Python3




# Defining a list
list = [{1, 2, 3, 4}, ['1.1', '2.2']]
  
# clearing the list
list.clear()
  
print(list)

Output:

[]
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!