String concatenation vs. string substitution in Python

前端 未结 9 1624
暖寄归人
暖寄归人 2020-11-29 17:13

In Python, the where and when of using string concatenation versus string substitution eludes me. As the string concatenation has seen large boosts in performance, is this (

9条回答
  •  执笔经年
    2020-11-29 17:41

    "As the string concatenation has seen large boosts in performance..."

    If performance matters, this is good to know.

    However, performance problems I've seen have never come down to string operations. I've generally gotten in trouble with I/O, sorting and O(n2) operations being the bottlenecks.

    Until string operations are the performance limiters, I'll stick with things that are obvious. Mostly, that's substitution when it's one line or less, concatenation when it makes sense, and a template tool (like Mako) when it's large.

提交回复
热议问题