Menu Close
Python list clear method

Python List Clear() Method

In this Python list method tutorial, You will learn about the Python list clear() method. clear in Python is used to clear or empty the list. In Python, clear is a built-in function.
In the previous Python list method tutorial, we have seen all about the list append() method.

Python list clear() method:

In Python, the list clear() method is a built-in method that is used to clear the elements of the list or clean the list.

Syntax of Python list clear method:

list.clear()

Return value of clear() method.

Return value of clear() function in Python is None.

Python List Clear() Method Parameter:

In Python, list clear function does not accept any parameter.

Example 1:

Here, we will clear the fruits list using list clear() function.

fruits = ['apple', 'banana', 'cherry']
fruits.clear()
print(fruits)

Output

[]

Example 1:

fruits = ['apple', 'banana', 'cherry']
car = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}

fruits.append(car)
print(fruits)
fruits.clear()
print(fruits)

Output

['apple', 'banana', 'cherry', {'brand': 'Ford', 'model': 'Mustang', 'year': 1964}]
[]

Conclusion

In this tutorial, you have learned about the Python list clear method. clear function in Python allow us to clear or clean all the items of the list. Python list clear function is a built-in function.

If you like this Python list append method tutorial, Please share comment and share with your friends who want to learn Python programming.

For More Reference:- Click Here

Python List extend() method

Related Posts