How to erase only the first element in the list

Asked 2 years ago, Updated 2 years ago, 146 views

[0, 1, 2, 3, 4] -> [1, 2, 3, 4]

I'd like to remove the first element of the list together. Is there a function that does this? As I did, I don't think I need to use the for statement, but I don't know what function to use.

a = [0, 1, 2, 3, 4]

b = [i for i in a[1:]]

list python remove

2022-09-22 22:18

1 Answers

Remove the ith item of s and return the ith item

>>> l = [0, 1, 2, 3, 4]
>>> l.pop(0)
0
>>> l
[1, 2, 3, 4]

Same as s[i:j] = []

>>> l = [0, 1, 2, 3, 4]
>>> del l[0]
>>> l
[1, 2, 3, 4]

l[1:] copies from the second element of itable to return

>>> l = [0, 1, 2, 3, 4]
>>> l = l[1:]
>>> l
[1, 2, 3, 4]


2022-09-22 22:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.