To remove the first element from a Python list, you can use the pop() method with an index of 0:

my_list = [1, 2, 3, 4]
my_list.pop(0)
print(my_list)  # Output: [2, 3, 4]

Alternatively, you can use slicing to create a new list without the first element:

my_list = [1, 2, 3, 4]
new_list = my_list[1:]
print(new_list)  # Output: [2, 3, 4]

Note that the pop() method modifies the original list, while slicing creates a new list.

python list remove first element

原文地址: http://www.cveoy.top/t/topic/buS7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录