some_list[-1] is the shortest and most Pythonic.

In fact, you can do much more with this syntax. The some_list[-n] syntax gets the nth-to-last element. So some_list[-1] gets the last element, some_list[-2] gets the second to last, etc, all the way down to some_list[-len(some_list)], which gives you the first element.

You can also set list elements in this way. For instance:

>>> some_list = [1, 2, 3]
>>> some_list[-1] = 5 # Set the last element
>>> some_list[-2] = 3 # Set the second to last element
>>> some_list
[1, 3, 5]

Note that getting a list item by index will raise an IndexError if the expected item doesn't exist. This means that some_list[-1] will raise an exception if some_list is empty, because an empty list can't have a last element.

Answer from Sasha Chedygov on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › python › get the last element of a list in python
Get the last element of a list in Python | Sentry
May 15, 2023 - The Problem How do I get the last element of a list in Python? The Solution In Python, we can get the last element of a list using index notation. A positive…
Discussions

Print last digit in Numpy Array - Geographic Information Systems Stack Exchange
I'm sure this is pretty basic, but is there a way to print a certain indexed portion of each segment in an array? For example, if I have the numpy array: ([1,2,3], [4,5,6], [7,8,9]) I'd like to p... More on gis.stackexchange.com
🌐 gis.stackexchange.com
June 16, 2014
Is it possible to grab the last element of a numpy array with a negative slice?
You can't loop from negative to postive slice values as they don't "wrap". a[-2:2] would also give an empty array. More on reddit.com
🌐 r/learnpython
8
1
December 15, 2021
What is the easiest way to access the last element of a list?
Question Is there a way to find the last item in a list without using the len() function? Answer The last item in a list can be found using the index value computed by len() - 1 for the list. A short-hand for this is to use an index value of -1. For any list, accessing the index of [-1] will ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
8
June 9, 2018
Is there a way to call the last element of an array (not a list)? I can't find anything on the numpy website. TIA
Just call A[-1] More on reddit.com
🌐 r/learnpython
2
6
January 16, 2019
🌐
Reddit
reddit.com › r/learnpython › finding last index of some value in a list in python
r/learnpython on Reddit: Finding last index of some value in a list in Python
August 5, 2024 -

Let's say v is a list or a tuple.

To find the last occurrence of value in v we would need to compute len(v) - 1 - v[::-1].index(value)

Why is this? Why must we subtract the last term from len(v) - 1? Why does simply writing v[::-1].index(value) give the wrong result?

In fact, what does v[::-1] actually do? Doesn't it reverse the list/tuple? If it does reverse it, then v[::-1].index(value) should give the last occurrence of value in v, but for some reason it does not work like that.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-how-to-get-the-last-element-of-list
Get the Last Element of List in Python - GeeksforGeeks
July 11, 2025 - The simplest and most efficient method uses negative indexing with a[-1]. In Python, we can use -1 as an index to access the last element directly.
🌐
Better Stack
betterstack.com › community › questions › how-to-get-last-element-in-list-in-python
How do I get the last element of a list in Python? | Better Stack Community
January 26, 2023 - You can also use the len() function to get the length of the list and use it to index the last element. For example: ... Both of these approaches will work regardless of the length of the list.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python get the last element of a list
Python Get the Last Element of a List - Spark By {Examples}
May 31, 2024 - What is the pop() method, and how can I use it to get the last element? The pop() method is a built-in method in Python that removes and returns the last element from a list. It can be used to both retrieve and remove the last element simultaneously.
🌐
Esri Community
community.esri.com › t5 › python-questions › how-to-get-the-last-element-of-a-polyline-array › td-p › 408699
Solved: How to get the last element of a polyline array? - Esri Community
July 2, 2013 - Solved: To my surprise, it is impossible to get the last element of an array from a polyline (which is a arcpy.arcobjects.arcobjects.Array, so not a normal Python
Find elsewhere
🌐
Jessica Temporal
jtemporal.com › the-last-of-a-list-in-python
The last of the list with Python | Jessica Temporal
September 11, 2023 - Use the len() size function to get the length of the list and subtract 1 to get the index of the last element in that list. And that’s ok! It works. However, Python presents a more elegant way of doing this, see:
🌐
YouTube
youtube.com › the renegade coder
4 Ways to Get the Last Element of a List in Python - YouTube
Learn how to retrieve the last item of a list in Python with The Renegade Coder. Topics covered include negative indexing, iterable unpacking, and more. Cont...
Published   October 25, 2019
Views   1K
🌐
freeCodeCamp
freecodecamp.org › news › python-get-last-element-in-list-how-to-select-the-last-item
Python Get Last Element in List – How to Select the Last Item
March 15, 2022 - After using the pop() method, we got the value of the last element printed. But then when we print the list to the console, we can see that the last item no longer exists. In this article, we learned how to select the last item in a list using ...
🌐
Vultr
docs.vultr.com › python › examples › get-the-last-element-of-the-list
Python Program to Get the Last Element of the List | Vultr Docs
December 11, 2024 - The output will display 9. This method is the most straightforward when you know the list contains at least one element. Check if the list is non-empty before accessing its content. Use an if statement to prevent errors such as an IndexError. ... This approach ensures error-free execution by handling empty lists effectively. Understand that list.pop() not only retrieves but also removes the last element from the list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-first-and-last-elements-of-a-list
Get first and last elements of a list in Python - GeeksforGeeks
Unpacking allows us to extract the first and last elements while ignoring the rest. Using first, *_, last = a gives the first and last elements directly.
Published   July 11, 2025
🌐
PythonHow
pythonhow.com › how › get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
my_list = [1, 2, 3, 4] # using the pop() method to remove and return the last element last_element = my_list.pop() # using slicing to get a copy of the last element last_element = my_list[-1:] Note that the pop() method only works if the list is not empty. If the list is empty, it will raise ...
🌐
Python Shiksha
python.shiksha › home › tips › 7 ways to get the last element of a list in python
7 ways to Get the last element of a list in Python - Python Shiksha
August 1, 2022 - As we can see that we were able to get the last element by using the traversing the list in reverse order and fetching the first element of the reversed list. pop() is a very common and famous function in almost every language that can be used to delete the last element of an array, list etc.
🌐
Reddit
reddit.com › r/learnpython › is it possible to grab the last element of a numpy array with a negative slice?
r/learnpython on Reddit: Is it possible to grab the last element of a numpy array with a negative slice?
December 15, 2021 -

I have an array, a, which can be thought of as symmetric (the beginning holds some vectors, and the end holds their complements).

In order to make my code more tidy, I would like to just use negative indexing to get the original vectors and their complements. However, I can't figure out how to grab the last element of the array with negative indexing. Is this possible?

import numpy as np
start = 1 
stop = 3 
a = np.array([1,2,3,4,5,6,7,8]) 
a[start:stop] 
a[-stop:-start]

This setup works for all situations except where I need to grab the first/last element of the array. When start = 0, it returns an empty array.

🌐
Stack Abuse
stackabuse.com › python-get-last-element-in-list
Python: Get Last Element in List
March 2, 2023 - In this tutorial, we'll take a look at how to get the last element in a Python list with code examples and compare them to adhere to best coding practices.
🌐
Quora
quora.com › How-do-I-find-the-last-element-of-a-list-in-Python
How to find the last element of a list in Python - Quora
Answer (1 of 3): > lets say we have a list of words [code]words = [‘One’, ‘Hello’, ‘Welcome’] [/code] * One Way to do this, is by counting the negative way. [code]print(words[-1]) # will print 'Welcome' (the answer you want) print(words[-2]) # will print 'Hello' print(words[-3]) ...
🌐
TutorialsPoint
tutorialspoint.com › How-to-get-the-last-element-of-a-list-in-Python
How to get the last element of a list in Python?
August 23, 2023 - Consider a Python list. To access a range of elements in a list, you must slice it. One method is to utilize the simple slicing operator, i.e. colon (:) With this operator, one can define where to begin slicing, where to end slicing and the step. List slicing creates a new list from an old one. ... Get the last element of the input list using slicing and create a variable to store it.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
What is the easiest way to access the last element of a list? - Python FAQ - Codecademy Forums
June 9, 2018 - Question Is there a way to find the last item in a list without using the len() function? Answer The last item in a list can be found using the index value computed by len() - 1 for the list.