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
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now
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
Open Code Manager We are hiring