I want to check in a string from the last character to the first one using while loop in python.
Linux - Ubuntu - I am using Atom text editor.
fruit = 'banana'
letter = fruit[5]
length = len(fruit)
index = 5
while index > len(fruit):
letter = fruit[index]
print(letter)
index = index - 1
the terminal lists the characters right but does that twice and at the end displays out of range error. check:
a
n
a
n
a
b
a
n
a
n
a
b
Traceback (most recent call last):
File "youtube.py", line 5, in <module>
letter = fruit[index]
IndexError: string index out of range