python delete a list code example

Example 1: delete all elements in list python

mylist = [1, 2, 3, 4]
mylist.clear()

print(mylist)
# []

Example 2: how to delete list python

# delete by index
a = ['a', 'b', 'c', 'd']
a.pop(0)
print(a)
['b', 'c', 'd']

Example 3: python list remove item by value

l = ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']
print(l)
# ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']

l.remove('Alice')
print(l)
# ['Bob', 'Charlie', 'Bob', 'Dave']

Example 4: How do you clear a list

lst = [1,2,3,4,5,6,7,8,9,10]
lst.clear()