[Python] Python and concatenating strings

Rob Hudson rob at euglug.net
Tue Feb 27 15:39:33 PST 2007


I'm working on some code and I'm doing a lot of this:

content = ''
if blah:
	content += 'something'
if blah2:
	content += 'something else'

There's lots of that.  Is there a faster way to build a string?

I know this is particularly slow in Java since it allocates only enough 
for the string each time.  If you know you're going to do a lot of this, 
they recommend StringBuilder.

I'm curious if Python is similar.

Thanks,
Rob


More information about the Python mailing list