What is the most efficient string concatenation method in python?

PythonServer Side ProgrammingProgramming

The best way of appending a string to a string variable is to use + or +=. This is because it's readable and fast. They are also just as fast. Other than this, if you're working with 2 strings, append() can also be used.

If you are concatenating a list of strings, then the preferred way is to use join() as it accepts a list of strings and concatenates them and is most readable in this case.

If you are looking for performance, append/join is marginally faster there if you are using extremely long strings. 

raja
Published on 18-Dec-2017 12:36:04
Advertisements