Please see https://docs.python.org/2/library/functions.html#range to see how range works. I can see it may be initially confusing to read the documentation but hope my explanation below, for your case, helps.
Specifically these lines from the above doc answers your question:
' The full form returns a list of plain integers [start, start + step, start + 2 * step, ...]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop'
In your case start=2(len(data)-1), stop =-l and step=-1. So the potential list of integers would be [2, 2-1, 2-2*1, 2-3*1 ...] which is [2,1,0,-1 ...]. However since your step is negative, i.e, -1, the last element would be smallest (start + i*step) greater than stop. In the potential list, the smallest item greater than stop, i.e greater than -1 is 0. So range(len(data)-1, -1, -1) returns [2,1,0]
range(len(data)-1, -1, -1)before assuming anything about the stopping point (especially since the evidence point against your assumption)rangeactually stops before the upper limit. Presumably it behaves this way to ensurefor i in range(3)will iterate 3 times as most people would expect, withitaking on the values[0, 1, 2]. In your case,range(2, -1, -1)outputs[2, 1, 0], which corresponds to the indices of the output you're seeing.