Unundestable loop in python strings lesson

Hello guys, I am started learning Python and doing the computer science career path.
Right now I stucked a bit in Python strings, especially I can’t understand how this loop is working,
the task is: Inside password_generator, create a forloop that iterates through the indices of user_name by going from 0 to len(user_name).
The loop should create the password by shifting all the letters of user_name one to the right. To do so, add the letter at the previousindex of user_name to password with each pass of the loop.
After the for loop but still within the definition of password_generator, return the password.

And the code is:
def password_generator(user_name):
password = “”
for i in range(0, len(user_name)):
password += user_name[i-1]
return password

I would be very grateful if someone can explain every step of this code, and how is it working!