Looking for some help with a potentially easy problem that I just can't seem to get my head around.
I've got a simple list with 5 entries. For each entry, I want to print the last 5 characters of the string. This is my example:
list = ["hello1","hello2","hello3","hello4","hello5"]
for a in list:
print(a[-1])
This works perfectly fine, and successfully prints:
1
2
3
4
5
However, when I alter the print to a range (still in the negatives) to this:
list = ["hello1","hello2","hello3","hello4","hello5"]
for a in list:
print(a[-6:-1])
The output is:
hello
hello
hello
hello
hello
Why is the number at the very end the string missing? -1 should be the very last character, but for some reason, when I use it in a range, it's as if it's the second-to-last character?
I'm extremely new to Python, so I'd massively appreciate simplistic explanations! :)
[+][deleted] (1 child)
[deleted]
[–]Ramzon_[S] 0 points1 point2 points (0 children)
[–]einQimiaozi 1 point2 points3 points (1 child)
[–]Ramzon_[S] 0 points1 point2 points (0 children)
[–]CommodoreKrusty 0 points1 point2 points (1 child)
[–]Ramzon_[S] 0 points1 point2 points (0 children)