I'm new to programming, and obviously I can easily run a program to get the answer, but I want to get a clearer and better understanding of why this code runs "dessert". I understand len(s) is the length of the number, but what about the three numbers "-1, 0 -1"? Can I get a detailed explanation of why this prints dessert?
s = "stressed"
for i in range(len(s)-1, 0, -1):
print(s[i], end = " ")
s t r e s s e d
0 1 2 3 4 5 6 7
range function : range(start, stop, step)
len(s) = 8
len(s-1)= 7
the loop starts at 7 stops at 0 and counts(steps) bacwards by 1 (-1) so , the loop prints
7 6 5 4 3 2 1
d e s s e r t