Python List - clear method

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:

# 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:

Contents of the list:
[]
Length of the list:
0

Copyright 2024 © pythontic.com