Python Lists – Remove the first item in a list

In this post we will be creating a Python script that will remove the first item within a list. Lists in Python are a means of storing multiple items in to a single variable.

To do this we will be using the ‘pop()’ method which removes the item at the given position in the list, and returns its value. See the snippet of code below as an example. Our list contains four items and it is the ‘abc’ entry we are wanting to remove.

List = ['abc', 'def', 'ghi', 'jkl']
print(List.pop(0))

The above would return the following as output. The Python ‘pop()’ method will remove the ‘abc’ entry from our list and return it to output.

abc
>>> 

Our list would then be seen as below with the initial ‘abc’ entry removed.

['def', 'ghi', 'jkl']
>>> 

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply