A real python

Python - Remove the first item in a list

You can remove the first item in 3 ways.

To remove the first item in a list in Python, you can use one of these methods:

Using the pop() method

1
2
my_list = [1, 2, 3, 4, 5]
first_item = my_list.pop(0)

Using list slicing

1
2
my_list = [1, 2, 3, 4, 5]
my_list = my_list[1:]

Using the del keyword

1
2
my_list = [1, 2, 3, 4, 5]
del my_list[0]

Documentation

Follow me

Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.

Credit: Photo by Pixabay.

Licensed under CC BY-NC-SA 4.0
License GPLv3 | Terms
Built with Hugo
Theme Stack designed by Jimmy