I know that concatenating two strings using the +=
operator makes a new copy of the old string and then concatenates the new string to that, resulting in quadratic time complexity.
This answer gives a nice time comparison between the +=
operation and string.join(str_list, '')
. It looks like the join()
method runs in linear time (correct me if I am wrong). Out of curiosity, I wanted to know how the string.join(str_list, '')
method is implemented in Python since strings are immutable objects?