The list slicing syntax:
sample_list[ start : end : step]
start
is inclusive, end
is exclusive.
The default start
is 0
, default end
is the end, default step
is 1
.
Given the following list, please finish the exercises:
sample_list = [0,1,2,3,4,5,6,7,8,9]
How can we get the first item?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get the last item?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get the first 3 items?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get the last 3 items?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get a copy of the list?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get a copy of the list without first item?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How can we get a copy of the list without last item?
sample_list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]