Hello! For this exercise, I wanted to try adding start and end indeces just for practice, to make sure I understood.
The solution wanted by the exercise, “stride length”:
exercise: Create a variable, backwards_by_tens
, and set it equal to the result of going backwards through to_one_hundred
by tens. Go ahead and print backwards_by_tens
to the console.
to_one_hundred = range(101)
backwards_by_tens = to_one_hundred[::-10]
print backwards_by_tens
prints
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 0]
If I try to go from first negative to first positive index, the 0 value doesn’t print even though no index goes lower than 0:
backwards_by_tens = to_one_hundred[-1:0:-10]
print backwards_by_tens
it prints [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
If I try to go from first negative index to what I think is the last negative index, the 0 value also doesn’t print
backwards_by_tens = to_one_hundred[-1:-101:-10]
print backwards_by_tens
[100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
it only prints 0 when I go to -102 (in to_one_hundred[-1:-102:-10]), which I guess makes sense if there are 102 values from 0 to 101. Is this a side effect of the negative index starting from -1 instead of from a 0? I’m not sure how to count indeces when going backwards. Thank you in advance for your help.