像 C# 中的 StringBuilder 这样的 Python 字符串类? [英] Python string class like StringBuilder in C#?
本文介绍了像 C# 中的 StringBuilder 这样的 Python 字符串类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python 中是否有类似于 C# 中的 StringBuilder
的字符串类?
Is there some string class in Python like StringBuilder
in C#?
推荐答案
没有一对一的相关性.对于一篇非常好的文章,请参阅 Python 中的高效字符串连接:
There is no one-to-one correlation. For a really good article please see Efficient String Concatenation in Python:
在 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 最快的方法如下.它非常紧凑,也很容易理解:
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)])
这篇关于像 C# 中的 StringBuilder 这样的 Python 字符串类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文