Python Remove a List Item
Remove a List Item
There are several methods to remove items from a list:
Example
The remove() method removes the specified item:
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
Try it Yourself »
thislist.remove("banana")
print(thislist)
Example
The pop() method removes the specified
index, (or the last item if index is not specified):
thislist = ["apple", "banana", "cherry"]
thislist.pop()
print(thislist)
Try it Yourself »
thislist.pop()
print(thislist)
Example
The del keyword removes the specified
index:
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)
Try it Yourself »
del thislist[0]
print(thislist)
Example
The del keyword can also delete the list
completely:
thislist = ["apple", "banana", "cherry"]
del thislist
Try it Yourself »
del thislist
Example
The clear() method empties the list:
thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)
Try it Yourself »
thislist.clear()
print(thislist)
Related Pages
Python Lists Tutorial Lists Access List Items Change List Item Loop List Items List Comprehension Check If List Item Exists List Length Add List Items Copy a List Join Two Lists