Here is how to get the last item of a list in Python.

# Create a sample list
images = ['house.png', 'street.png', 'forrest.png'] 
# Get the last item
last = images[-1] 
# Print the last item




The -1 index always returns the last item of a Python list. The -2 index would return the item before the last item, and so on. 

Related HowTos
Do dictionary comprehension
Do list comprehension
Create a virtual environment
Create a new file
Merge two lists
Extract items from two different lists into one list
Check if a text file is empty
Randomly select an item from a list
Generate a random integer
Break a while loop
Create a pandas DataFrame from a dictionary
Create a pandas DataFrame from a list
Delete a column from a pandas dataframe
Access a column of a pandas dataframe
Create a class
Make a webpage request
Get the first two characters of a string
Recommended Course

Learn Flask development and learn to build cool apps with our premium Python course on Udemy.

Mailing List

We will keep you Python-motivated if you subscribe below.