Martin McBride
Jan 24, 2025

Another reason to use join rather than + is that string are immutable, so every time python adds two strings it has to create a brand new string to hold the result.

If you used a loop to concatenate a list of 100 strings, Python would potentially need to create a string to hold the result of adding the first 2 strings in the list, then another string to hold the result of adding the first 3 strings in the list, then another string to hold the result of adding the first 4 strings in the list, and so on. all the way up to 100.

Martin McBride
Martin McBride

Responses (1)