Chrome Extension

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
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Output
sharpner
['pen', 'pencil', 'sharpner']
['pencil', 'sharpner']
board

'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?
0 Comments
Join Devsheet Ask a Question