Menu Close

How to get the last element of a Python list?

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

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

How to get the last element of a Python list?

To get the last element of a Python list, we can use -1 as the index in the square brackets.

For instance, we write:

some_list = [1, 2, 3]
print(some_list[-1])

Then we see 3 logged since index -1 is the last element of the list.

Conclusion

To get the last element of a Python list, we can use -1 as the index in the square brackets.

Posted in Python, Python Answers