Fix Python – Python string class like StringBuilder in C#?

Question

Asked By – icn

Is there some string class in Python like StringBuilder in C#?

Now we will see solution for issue: Python string class like StringBuilder in C#?


Answer

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)])

This question is answered By – Andrew Hare

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0