del vs clear in python code example
Example 1: delete all elements in list python
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []
Example 2: how to clear a list in python
yourlist = [1,2,3,4,5,6,7,8]
del yourlist[:]
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []
yourlist = [1,2,3,4,5,6,7,8]
del yourlist[:]