I have below list
l1 = [1,2,3,4,5,6,7,8,9]
I want to understand below result :-
>>> l1
[4:8:-2]
Please explain result of above slicing.
I have below list
l1 = [1,2,3,4,5,6,7,8,9]
I want to understand below result :-
>>> l1
[4:8:-2]
Please explain result of above slicing.
slicing is [start:stop:step]
do like this,
When you are steping it from backward then you have to take index from back,
>>> l1 = [1,2,3,4,5,6,7,8,9]
>>> l1[8:4:-2]
[9, 7]
You are asking to start from index 4
till index 8
by step -2
, so you are asking to get index 8
and 6
and avoiding index 4
.