Format strings vs concatenation

前端 未结 7 672
天命终不由人
天命终不由人 2020-11-28 09:18

I see many people using format strings like this:

root = \"sample\"
output = \"output\"
path = \"{}/{}\".format(root, output)

Instead of si

7条回答
  •  天涯浪人
    2020-11-28 09:40

    It's for looks and the maintaining of the code. It's really easier to edit your code if you used format. Also when you use + you may miss the details like spaces. Use format for your and possible maintainers' good.

提交回复
热议问题