python
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
Output
sharpner
['pen', 'pencil', 'sharpner']
['pencil', 'sharpner']
board
['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?
Similar Posts
- Python collection - Tuples in python
- Python collection - sets in python
- Python collection - Dictionaries in python
- Convert pandas DataFrame to python collection - dictionary
- Create a flat list from list of lists in Python
- Check if a list exists in a list of lists Python
- Convert a List of Strings to List of Integers in Python