Python ProgrammingPython Programming

How to get first and last item from list in Python?

You can use slicing notation to fetch first and last item of list.
testList = ["Canada", "Japan", "London", "Germany", "Africa", "Italy"]
 
print(testList[0])  # First item
print(testList[-1])  # Last item
Output
Canada
Italy