Joe Bonamassa - Muddy Wolf at Red Rocks. | Joe Cocker - Fire it Up Live. | Joe Satriani - Satchurated Live in Montreal.

, asked
Views : 3

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

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

 

 

 

 

 

1 Answer
Malhar Lathkar

Python sequence, including list object allows indexing. Any element in list can be accessed using zero based index. If index is a negative number, count of index starts from end.  As we want last element in list, use -1 as index.

>>> L1=[1,2,3,4,5]
>>> print (L1[-1])
5

Advertisements
Related Questions