Python List clear()

Python List clear() method

Python List clear() method removes all the items from the list. The method makes the list empty.

In this tutorial, you will learn the syntax of, and how to use List clear() method, with examples.

Syntax of List clear()

The syntax of List clear() method is

list.clear()

Parameters

clear() method take no parameters.

Return value

append() method returns None.

Please note that clear() method modifies the original list.

Examples

1. Clear the list in Python

In the following program, we take a list my_list which is initialized with [52, 41, 63]. We have to make this list empty.

Call clear() method on the list my_list, and the items in the list shall be cleared.

Python Program

my_list = [52, 41, 63]
my_list.clear()
print(my_list)
Run Code Copy

Output

[]

Summary

In this tutorial of Python Examples, we learned about List clear() method, how to use clear() method to make a given list empty, with syntax and examples.

Related Tutorials

Code copied to clipboard successfully 👍