So, your list is li=[1,2,3,4,5,6,7]
First, understand what exactly happens in slicing.
Slicing can't be done in backward direction without using step.
Take an example, we wan't to print [7, 6, 5, 4, 3, 2]
, we can't do this using li[-1:0]
. because, slicing can't go backward as stated (we can't go backwards from index -1 to 0), and will return empty list []
.(We have to do this using li[-1:0:-1]
)
So what happens here is:
you have a list li[x:y]
, using a negative step will swap the indexes as li[y:x]
.(Once swapping of indexes is done, you should consider it as a positive step) and then print out your output w.r.t. your provided step(only the magnitude).
Now, all that I mentioned above might seem useless, but it would help you understand next part.
So, coming to your question, when you write li[0:-3:-2]
, first,indexes are swapped. So, it is same as li[-3:0:2]
. and as I have stated above, we can't go backwards (index -3
to 0
) without using a negative step, so it returns the empty list.
but, when you give input as li[:-3:-2]
, It swaps the indexes and becomes li[-3::2]
and we now easily know what will be the output ([7]
).
So, don't consider the blank space in [:-3:-2]
as 0
but as left end.(for better understanding)
Hope this helped.