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
๐ŸŒ
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. ... We can also find the last element by using len() function.
Discussions

Finding last index of some value in a list in Python
v[-1] is the last element of a list or tuple. v[-2] is the second last. The syntax where you're doing v[a:b:c], is known as slice notation. a is the start position, b is the end position, and c is the increment. a and b default to the start and end. c defaults to 1, so... v[::] refers to all elements from start to end. Useful for copying whole content somewhere, as distinct from assigning the list to a new variable. v[::2] refers to every second element v[::-1] is all the element in reverse. v[::-2] is every second element in reverse. v[5:] is all elements from 5 to the end. v[:5] is all elements from the start to < 5, so v[:5] and v[5:] do not overlap. More on reddit.com
๐ŸŒ r/learnpython
6
5
August 5, 2024
Looping until the second to last element in a list, what's best practice?
for item in the_list[:-1] More on reddit.com
๐ŸŒ r/learnpython
23
3
January 11, 2024
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
How to get the last element of list in tcl?
set foo {1 2 3} puts [lindex $foo end] More on reddit.com
๐ŸŒ r/Tcl
3
6
September 21, 2023
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ get the last element of a list in python
Python Last Element in List Using Negative Indexing | Sentry
July 3, 2026 - Access the last element of a Python list using negative index notation with [-1], which counts positions from the end of the list instead of the start
๐ŸŒ
Jessica Temporal
jtemporal.com โ€บ the-last-of-a-list-in-python
Getting the last element of a list in Python | Jessica Temporal
June 20, 2026 - 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:
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ last element in list python
Program to Get the Last Element in List in Python - Scaler Topics
May 18, 2023 - This function constructs a callable that assumes an iterable object as input and fetches the n-th element out of it. We can use this function to get the last element in the list in Python by creating a callable object using the index as -1.
๐ŸŒ
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.

Find elsewhere
๐ŸŒ
JanBask Training
janbasktraining.com โ€บ community โ€บ python-python โ€บ how-do-i-get-the-last-element-of-a-list
How do I get the last element of a list? - Python
June 23, 2025 - Python offers a few simple ways to do this, depending on your needs. ... This is more verbose and rarely needed, but useful if you're doing calculations with indices. ... If the list is empty, accessing my_list[-1] will throw an IndexError. You can avoid that with a check: if my_list: print(my_list[-1]) else: print("List is empty") ... If you only want to peek at the last element without modifying the list, negative indexing (my_list[-1]) is still the best and most Pythonic choice free online games.
๐ŸŒ
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 ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-last-n-elements-from-given-list
Python | Get Last N Elements from Given List - GeeksforGeeks
It first reverses the list using slicing ([::-1]), then iterates over the first N elements, appending them to a new list res. Finally, it reverses res to restore the original order and prints the last N elements.
Published: July 11, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-first-and-last-elements-of-a-list
Get first and last elements of a list in Python - GeeksforGeeks
Then, res = [first, last] creates a new list [1, 4]. List comprehension can be used to pick specific positions from a list. You can get the first and last elements using [a[i] for i in (0, -1)]. This method works well but is less readable compared ...
Published: July 11, 2025
๐ŸŒ
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]) ...
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
New: Practice Python, JavaScript & SQL with AI feedback โ€” Try ActiveSkill free โ†’ ร— ... To get the last element of a list in Python, you can use the index -1.You can also use the pop() method to remove and return the last element of a list. This method removes the element from the list, ...
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ python โ€บ first, last, initial, head, tail
First, last, initial, head, tail of a Python list - 30 seconds of code
May 15, 2024 - def last(lst): return lst[-1] if lst else None last([1, 2, 3]) # 3 last([]) # None ยท To get all elements of a list except the last one, you can use lst[:-1]. This will return all elements of the list except the last one, or an empty list if ...
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ get the last element of a list in python
Get the last element of a list in Python - PythonForBeginners.com
August 11, 2021 - We can create an itemgetter object to access the last element of a list. The itemgetter() method is defined in the operator module in python. The itemgetter() method takes the index as input which creates a callable object.
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ list โ€บ get-first-last-elements-python-list
How to Get the First and Last Elements of a Python List? - AskPython
April 5, 2023 - Use the below syntax to print the last element of a list. ... Slicing is a powerful feature that allows you to create a new list from an existing list by specifying the starting and ending indices. The new list is a portion of the original list, and it can be used for various purposes, such as processing specific data, managing memory usage, and more. We can use slicing to access the first and the last items in the list. ... Use the below syntax to get the first and the last element of a list.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.7 documentation
The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (โ€œlast-in, first-outโ€). To add an item to the top of the stack, use append(). To retrieve an item from the top of the ...
๐ŸŒ
Wyzant
wyzant.com โ€บ resources โ€บ ask an expert
In Python, how do you get the last element of a list? | Wyzant Ask An Expert
May 8, 2019 - Negative indexes refer to elements counting from the last element. So, mylist[-1] gives the last element of a list, mylist[-2] the second to last element, and so forth. ... Get a free answer to a quick problem.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-the-second-to-last-element-of-a-list-in-python
How to get the second-to-last element of a list in Python?
March 15, 2026 - Python lists support negative indexing, where -1 refers to the last element and -2 refers to the second-to-last element. This makes accessing elements from the end of a list straightforward.