First time using StackOverflow, apologies in-case of any issues.
In python,
list[::-1]
returns the reversed list
list[0:len(list)+1]
returns the complete list
So why list[0:len(list)+1:-1]
returns an empty list?
Further, for a list l= [0,1,2,3,4,5]
, if I want like [4,3,2]
:
Trying l[2:5:-1]
, returns an empty list. But l[2:5][::-1]
works.
Can anyone explain why this is happening? Or what is python actually doing when we slice a list, with a value for step?
Thanks in advance :)