How do you delete an item from a list in Python?
Experience Level: Junior
Tags: Python
Answer
To delete an item from the list, use del statement.
Example:
# The code belows deletes "amber" item from the list.
items = list["red", "amber", "green"]
del list[1]
Related Python job interview questions
How do you comment out code in Python using multi-line comment?
Python JuniorHow do you comment out code in Python using single-line comment?
Python JuniorHow do you add a new item to a list in Python?
Python JuniorHow do you display a number of items in a list in Python?
Python JuniorWhat is a private method in Python?
Python Junior