In this example we will show how to access the list items by specifying an index range that omits the start value in Python.
Source Code
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[:4])
Output:
['a', 'b', 'c', 'd']
In this example we will show how to access the list items by specifying an index range that omits the start value in Python.
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[:4])
Output:
['a', 'b', 'c', 'd']
In this example we will show how to access the list items by specifying an index range in Python.
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[1:4])
Output:
['b', 'c', 'd']
In this example we will show how to access the list items by specifying an negative index range in Python.
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[-4:-1])
Output:
['b', 'c', 'd']