In the context of this exercise, how does string concatenation work?
In string concatenation, each time a string is added, Python allocates memory to fit the total string, and then copies all the strings into that location in memory. So, if you were adding multiple strings together, like
string1 + string2 + ... + stringN
It would do this process during each concatenation, always adding from the very first string each time
string1 + string2 string1 + string2 + string3 ...
until it reaches the last added string.
As a result, concatenation with many strings can be inefficient, but for most problems that we will encounter, the time it takes will usually be negligible.
Whilst you could use loops there’s a built-in string method for this string.join() which is probably the most effective way to do it. I’d guess that it will pop up in later lessons but if not there are some relevant FAQs on the forums-