wordsmythe
0
Q:

how to clear a list in python

your_list = [1,2,3,4,5,6,7,8,9,10]
your_list.clear() #List becomes [] empty
7
mylist = [1, 2, 3, 4]
mylist.clear()

print(mylist)
# []
5
# this clear whole elements from list
thislist = ["apple", "banana", "cherry"]
thislist.clear()
5
yourlist = [1,2,3,4,5,6,7,8]
del yourlist[:]
3
# deletes whole list
thislist = ["apple", "banana", "cherry"]
del thislist
4

New to Communities?

Join the community