In generating a string, sometimes results are created one character at a time, or in chunks. From the function name I suspect that this particular algorithm was doing something like that.
If the process is iterative (happens inside a loop) a natural way to add the latest chunk to whatever has already been accumulated is to use a statement such as
password = password + new_chunk
which can nowadays be written more concisely as
password += new_chunk
This takes the existing value of the password
variable and adds the new chunk to it, replacing the old value of password
.
Executing this statement without having assigned a value to the password
variable would cause an exception, however (specifically you would see a NameError because the statement requires you to start with the existing value of password
, and it doesn't have one). So before the loop you assign the null string (the one containing no characters) to the variable, thereby avoiding an inconvenient but all too common error.