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
Python Last Element in List Using Negative Indexing | Sentry
July 3, 2026 - In Python, we can get the last element of a list using index notation. A positive index will give us a position in the list counting from the start, whereas a negative slice index will give us a position counting from the end.
🌐
Appdividend
appdividend.com › how-to-get-last-element-of-a-list-in-python
How to Get the Last Element of a List in Python
July 20, 2025 - The most recommended and Pythonic way to retrieve the last element of a list is to use negative indexing (list[-1]), provided the list is not empty. main_list = [1, 2, 3, 4, 5] last_element = main_list[-1] print("The last element of the list ...
🌐
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 - ... It’s less efficient than direct indexing because it involves memory allocation for the new list. Another way to get the last element is by using pop() method. This method removes and returns the last element of the list.
🌐
Vultr
docs.vultr.com › python › examples › get the last element of the list
Python Program to Get the Last Element of the List
December 11, 2024 - Recognize that Python lists support negative indexing, where -1 refers to the last element. Retrieve the last element of a non-empty list using negative indexing. ... 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.
🌐
PythonHow
pythonhow.com › how › get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
You can check if the list is empty using the len() function and handle the exception accordingly. Here is an example: my_list = [1, 2, 3, 4] if len(my_list) > 0: last_element = my_list.pop() else: # handle the empty list case last_element = None # or some other default value ...
🌐
LabEx
labex.io › tutorials › python-how-to-get-last-element-without-errors-in-python-418582
How to get last element without errors in Python | LabEx
This section explores various techniques to retrieve the last element without raising exceptions. def get_last_element(lst): if lst: ## Check if list is not empty return lst[len(lst) - 1] return None ## Example usage fruits = ['apple', 'banana', ...
Find elsewhere
🌐
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 - To get the last element of a list, you can use lst[-1]. This will return the last element of the list, or None if the list is empty.
🌐
TechBeamers
techbeamers.com › python-get-last-element-in-list
Python Get Last Element in List - TechBeamers
November 30, 2025 - my_list = [1, 2, 3, 4, 5] last_element_comprehension = my_list[-1] if my_list else None print(last_element_comprehension) # Output: 5 · List comprehension allows you to provide a default value (in this case, None), when the list is empty, avoid the “IndexError” that negative indexing and the shortcut [-1] may encounter. Python’s collections module comes with a deque class which provides an efficient way to get the last element of a list.
🌐
Python Guides
pythonguides.com › python-get-last-element-in-list
How To Get The Last Element Of A List In Python?
March 19, 2025 - We use a conditional statement to check if the list is empty. If the list is not empty, we proceed to access the last element using empty_list[-1]. However, if the list is empty, we print a message indicating that the list is empty. Read How to Check if Any Element in a List is Present in Another ...
🌐
sqlpey
sqlpey.com › python › python-get-last-element
Python Techniques for Retrieving the Last Element of a List Safely
November 4, 2025 - If clarity and explicit safety checks are paramount, especially for developers new to Python’s negative indexing, a conditional expression guards against the IndexError. def fetch_last_or_default(input_list, default_val=None): """Returns the last element or a specified default if the list ...
🌐
Milddev
milddev.com › python-last-element-in-list
Get Python Last List Element
Python’s negative indexing lets you count from the end. my_list[-1] is the last element, my_list[-2] is the second-to-last, and so on: ... Tip: Negative indexing is zero-cost. It translates directly to an offset from the end in C code, so ...
🌐
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 I have mentioned at he starting that we can simply get the last element by doing list[len-1], but if you are familiar with coding practices, you might me knowing that from the end of a list or array the concept of negative index is used.
🌐
CodeGenes
codegenes.net › blog › how-to-get-last-element-in-list-python
How to Get the Last Element in a List in Python — codegenes.net
If the list is not empty, we access the last element using negative indexing and print it. Otherwise, we print a message indicating that the list is empty. Negative indexing is the most concise and Pythonic way to get the last element of a 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 - Have you ever needed to get the last element of a list in Python, but weren't sure of the best way to do it? There are several different methods you can
🌐
Techie Delight
techiedelight.com › home › python › get last element of a list in python
Get last element of a list in Python | Techie Delight
July 7, 2026 - Negative indexing allows us to access elements from the end of a list by using negative numbers as indices. Since the negative indices start from -1, a[-1] fetch the last item of list a, a[-2] fetch second last item of list the a, and so on. This is indeed the shortest and the most Pythonic solution. Following is a simple example demonstrating usage of this: ... If the list is empty or the index is out of range of a list, it will raise an IndexError.
🌐
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 best 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. The list[-1] is the most preferable, ...
🌐
CoenRaets
jsonviewer.ai › python-get-last-element-in-list5-methods-with-code-examples
Python Get Last Element in List[5 Methods with Code Examples] - JSON Viewer
July 29, 2023 - The syntax “[-3:]” means starting from the third element from the end and going up to the last element. When working with lists, it’s essential to handle potential errors gracefully, especially when dealing with empty lists or lists with only one element.
🌐
CodeRivers
coderivers.org › blog › get-last-element-of-list-python
Retrieving the Last Element of a List in Python - CodeRivers
February 22, 2026 - If you want to get the actual element (not in a list), you can access the first (and only) element of the new list like this: last_element = my_list[-1:][0]. When retrieving the last element of a list, it's important to consider the case where the list is empty.