Python collection - List in python

list = ["pen", "pencil", "sharpner", "eraser", "board"]

print(list[2]) #print third element sharpner

print(list[:3]) #print items start index to 0 and less than index 3

print(list[1:3]) #print list start from index 1 and less than index 3

print(list[-1]) #print last element
['pen', 'pencil', 'sharpner']
['pencil', 'sharpner']

'List' is a python collection where you can assign multiple items to it and get them using its index start from 0. You can also modify the items of a list.

You can also pass the start and end index to get list of items according to the index.

Was this helpful?