quote[::-1]
will reverse the string much easier than that while loop :)
This is called extended slice notation. There's three parts to the slice notation, "String"[start_index:end_index:step]
>>> "abcdefg"[0:2]
'ab'
>>> "abcdefg"[2:3]
'c'
>>> "abcdefg"[::2]
'aceg'
Remember that indexes occur before the letter, so:
a b c d e f g
0 1 2 3 4 5 6 7
If you slice [0:2]
, you're getting:
|a b|c d e f g
0 1 2 3 4 5 6
if you slice [2:3]
you're getting:
a b|c|d e f g
0 1 2 3 4 5 6 7
and the last bit of the slice notation is how many steps you take per index. In my test case I used "2" which means it only throws an index every other number:
a b c d e f g
0 1 2 3
With the negative slice I used as answer to your problem, it steps backwards instead of forwards, starting at the end instead of the beginning. You need those first two colons to show Python you mean a slice (and not beginning at index -1, which would throw IndexError).
a b c d e f g
7 6 5 4 3 2 1 0
So it lays the indexes like so, and starts counting from zero until the end of the indexes (the beginning of the string).
Understand?