Python string class like StringBuilder in C#?

There is no one-to-one correlation. For a really good article please see Efficient String Concatenation in Python:

Building long strings in the Python progamming language can sometimes result in very slow running code. In this article I investigate the computational performance of various string concatenation methods.

TLDR the fastest method is below. It’s extremely compact, and also pretty understandable:

def method6():
  return ''.join([`num` for num in xrange(loop_count)])

Leave a Comment