Home >Backend Development >Python Tutorial >How to Delete List Elements by Index in Python?
How to Delete List Elements by Index
Question:
How to delete List Elements by Index Remove element from ?
Answer:
Use del and specify the index of the element to be deleted:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] del a[-1] print(a) # Output: [0, 1, 2, 3, 4, 5, 6, 7, 8]
del also supports slicing, which is used to delete a range of elements:
del a[2:4] print(a) # Output: [0, 1, 4, 5, 6, 7, 8, 9]
For more details, please see the following section of the tutorial:
The above is the detailed content of How to Delete List Elements by Index in Python?. For more information, please follow other related articles on the PHP Chinese website!