Python Programming
About Lesson

Slicing or accessing a group of list elements can be done by specifying the range of indexes. In this method, we will specify a start index and stop index. In the result, the value at start index will be included and value at the stop index will be excluded.

#Example
fruits = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(fruits[2:5])

#Example code to access all the values from starting index to specified index
fruits = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(fruits[:5])

#Example code to access all the values from specified index to the last element
fruits = [“apple”, “banana”, “cherry”, “orange”, “kiwi”, “melon”, “mango”]
print(fruits[3:])

You cannot copy content of this page