In Python programming, one can access list elements by passing the index of the list in brackets as integer values (zero-indexed: starting from zero to access the first element of the list and so on). Unlike some other languages, Python allows the use of negative index values to access elements of the list from left-to-right.
So, when you make use of list[-1] you can access the last element of the list.
# Examples list[-1]
python_list = [1, 2, 3, 4, 5, 6, 7]
last_element = python_list[-1]
print(last_element)
Output:
Let's take another example with a list of string values.
![Python list[-1] example](https://code2care.org/python/what-is-list-1-in-python-programming/images/Python%20list%5B-1%5D%20example.jpg)
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!