Python List - clear method

Remove all the elements in a python list object with the clear method and make the python list empty

List Updated 11 Sep 2016 1 min read

Method Name

clear

Method Signature

clear()

Overview

The clear() method removes all the elements of a Python list object and makes the list empty.

Parameters

None

Return Value

None

Example

python
# Example Python program that removes

            # all the elements present in a list instance

# A list of microprocessors

            mircoProcessors=['Intel4004', 'Intel8008', 'Intel8080', 'Intel8085']

# Clear the list

            mircoProcessors.clear()

# Print the list after clearing it

            print("Contents of the list:");

            print(mircoProcessors)

# Print the length of the list

            print("Length of the list:");

            print(len(mircoProcessors));

Output

Output
Contents of the list:

            []

            Length of the list:

            0