DEV Community

howtouselinux
howtouselinux

Posted on

how to get the last element of a list in python

>>> list1 = [1, 2, 3, 4, 5]
>>> print(list1[len(list1)-1])
5
>>> print(list1[-1])
5
>>> print(list1.pop())
5
>>>
Enter fullscreen mode Exit fullscreen mode

how to get the last element of a list in python

Top comments (0)