How to get the last element of a list in python ?

Published: January 22, 2018

DMCA.com Protection Status

Simple example on how to get the last element of a list in python

>>> a = [5,2,7,8]
>>> a[-1] # gets the last element
8

Another example on how to get the last but one element of a list in python:

>>> a[-2] # gets the second to last
7

References

Creative Commons License

To the extent possible under law, the person who associated CC0 with this work has waived all copyright and related or neighboringrights to this work.