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
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โ€ฆ
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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.

๐ŸŒ
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
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.
๐ŸŒ
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?
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.
๐ŸŒ
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 ...
Find elsewhere
๐ŸŒ
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.

๐ŸŒ
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 ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ 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
r/learnpython on Reddit: 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
January 18, 2019 -

For example, I am creating a bunch of arrays that are all different sizes, and I just need to be able to return the last element in each array. I tried creating array A, and then a value the length of A called Len, and then doing A[Len-1] but it didn't work.

๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-access-the-last-element-of-a-python-numpy-array
5 Best Ways to Access the Last Element of a Python NumPy Array โ€“ Be on the Right Side of Change
The item() method in NumPy can be used to retrieve a specific element from an array. By passing -1 as the argument, it retrieves the last element. This method is beneficial when you require the native Python scalar type instead of a NumPy type.
๐ŸŒ
PyTutorial
pytutorial.com โ€บ last-element-of-array-python
PyTutorial | 3 Methods to Get Last Element of Array in Python
March 7, 2020 - my_array = [10, 20, 30, 40, 50] # Array last_element = my_array[-1] # Get Last Element print(last_element) ... However, using the negative index -1 allows you to access the last element of the array's length easily. Slicing is a Python feature ...
๐ŸŒ
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]) ...
๐ŸŒ
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 11, 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.
๐ŸŒ
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.
๐ŸŒ
How to Use Linux
howtouselinux.com โ€บ home โ€บ 3 ways to get last element of a list in python
3 Ways to Get Last Element of a List In Python - howtouselinux
October 9, 2025 - The most effective way to get the last element of a list in Python is using the list[-1]. Python allows you to use negative indices, which count from the end of the list instead of the beginning. So list[-1] gets the last element, list[-2] gets the second to last.