xxxxxxxxxx
mylist = [1, 2, 3, 4]
mylist.clear()
print(mylist)
# []
xxxxxxxxxx
myList = ['Item', 'Item', 'Delete Me!', 'Item']
del myList[2] # myList now equals ['Item', 'Item', 'Item']
xxxxxxxxxx
characters = ["Eren Yeager", "Mikasa Ackerman", "Armin Arlert"]
del characters[:]
print(characters)
xxxxxxxxxx
l = [1, 2, 3] # your list
for idx, _ in enumerate(l):
del l[idx]
# OR
l.clear()
xxxxxxxxxx
myList = ['Item', 'Item', 'Delete Me!', 'Item']
myList.pop(2) # myList now equals ['Item', 'Item', 'Item']
xxxxxxxxxx
myList = ["Bran", 11, 33,"Stark"]
del myList[2] # output: [‘Bran’, 11, ‘Stark’]
xxxxxxxxxx
thislist = ["apple", "banana", "cherry"]
print(thislist)
del thislist
print(thislist)
xxxxxxxxxx
# Deleting list items
my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
# delete one item
del my_list[2]
print(my_list)
# delete multiple items
del my_list[1:5]
print(my_list)
# delete the entire list
del my_list
# Error: List not defined
print(my_list)
xxxxxxxxxx
l = list(range(10))
print(l)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
del l[0]
print(l)
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
del l[-1]
print(l)
# [1, 2, 3, 4, 5, 6, 7, 8]
del l[6]
print(l)
# [1, 2, 3, 4, 5, 6, 8]