String concatenation vs. string substitution in Python

前端 未结 9 1625
暖寄归人
暖寄归人 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:57

    Remember, stylistic decisions are practical decisions, if you ever plan on maintaining or debugging your code :-) There's a famous quote from Knuth (possibly quoting Hoare?): "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

    As long as you're careful not to (say) turn a O(n) task into an O(n2) task, I would go with whichever you find easiest to understand..

提交回复
热议问题