Click for All Topics
.clear()
method doesn’t take any argument and it doesn’t return anything.
Syntax –
list.clear()
Parameters –
Example 1-
my_list=[5,10,15,20,25,30]
print("Original list:",my_list)
my_list.clear()
print("Original list after clear:",my_list)
# Output -
# Original list: [5, 10, 15, 20, 25, 30]
# Original list after clear: []
.clear()
method with the my_list.Example 2- Clear an Empty list
lst=[]
print("Original list:",lst)
lst.clear()
print("Modified original list:",lst)
# Output -
# Original list: []
# Modified original list: []
Office:- 660, Sector 14A, Vasundhara, Ghaziabad, Uttar Pradesh - 201012, India