美文网首页
2018-04-10 讨论下str.join()与+

2018-04-10 讨论下str.join()与+

作者: 开子的私家地 | 来源:发表于2018-04-10 19:20 被阅读4次
    1. 在使用字符拼接时,str.join() 比 + 速度要快

    参考: https://docs.python.org/2.7/library/stdtypes.html
    CPython implementation detail: If s and t are both strings, some Python implementations such as CPython can usually perform an in-place optimization for assignments of the form s = s + t or s += t. When applicable, this optimization makes quadratic run-time much less likely. This optimization is both version and implementation dependent. For performance sensitive code, it is preferable to use the str.join() method which assures consistent linear concatenation performance across versions and implementations.

    相关文章

      网友评论

          本文标题:2018-04-10 讨论下str.join()与+

          本文链接:https://www.haomeiwen.com/subject/xignhftx.html