Menu Close

How to get the last element of a list with Python?

Sometimes, we want to get the last element of a list with Python.

In this article, we’ll look at how to get the last element of a list with Python.

How to get the last element of a list with Python?

To get the last element of a list with Python, we can use index -1.

For instance, we write

some_list = [1, 2, 3]
last = some_list[-1]

to get the last item from some_list with some_list[-1].

Conclusion

To get the last element of a list with Python, we can use index -1.

Posted in Python, Python Answers