I'm learning python and the "teacher" (a youtube channel) gives this function to revert the characters of a given array. I can't understand how the function reverts the characters.
1 alfa = "hello"
2 def reverser(string):
3 index = (len(string) -1)
4 new_string = ""
5 while index >= 0:
6 new_string += string[index]
7 index -= 1
8 print(new_string)
9
10 reverser(alfa)
Line 3: I know len returns the number of "hello" in this case. That -1 confuses me. Is it used to return the last character or to subtract the LEN result? why?
Line 4: ok we are creating a new string.
Line 6: No ideas...
Line 7: No ideas again...
I need help to understand it.
Python