Python indexing

Not 100% sure this is the correct thread, if it isn't please point me to the correct thread.

This is a pretty basic question but I'm just having a little trouble understanding. I'm learning python and I try to solve basic problems just to learn more.

I had a exercise asking me to reverse a string a user would input. I eventually took a look at the solution for some help. It gave me the solution below. I'm wondering if someone can explain this string to me. "backwards = backwards + user_str[len(user_str) – 1 – i]"

What the goal of this is to access the last letter in the provided string and add it to the backwards variable. I understand everything up until the i. Why does it need to subtract i? Full program is below, thanks in advance.

user_str = input("Please enter a string:") user_str = str(user_str) user_str = user_str.lower()

backwards = ""

for i in range(len(user_str)): backwards = backwards + user_str[len(user_str) – 1 – i)

print (backwards)

submitted by /u/Mcl0vinit
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/303MCRf

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close