Shifting characters in a string

def password_generator(user_name):
    password = ""
    for i in range(0: len(user_name)):
        password += user_name[i-1]
    return password

For the if statement, what is the difference between using range(0: len(user_name)) and range(len(user_name))


range(0: len(user_name) You are explicitly mentioning the start point to be 0 whereas, in range(len(user_name)) the range() function is using default value for start point; Which happens to be 0(zero).


Does this code even run? I get a syntax error. You use a colon (:) to separate the arguments, this should be a comma (,)


@java9059758472, @stetim94 is correct. Range doesn’t accept colon[:] it requires a comma[,] to separate the first and second argument.

Sorry, as I used colon in my previous answer. But, the explanation is still correct.

Exactly, given you already covered that, I didn’t feel the need to touch on it :wink: