r/learnpython • u/ironwaffle452 • May 09 '25
Python slicing, a[len(a)-1:-1:-1]
Hi, basic python question.
why this doesnt work?
a="hello"
a[len(a)-1:-1:-1]
#a[start:stop:step] start index 4, stop index -1 (not inclusive so it will stop at 0), step -1 All ai's saying Gibberish.
0
Upvotes
1
u/RaidZ3ro May 09 '25
If I understand correctly you want to step backwards from the second last character until the first.
Note: Start index is inclusive.
Stop index is exclusive.
-1 is the last characters index
-2 is the second last characters index.
What you want is: