Format strings vs concatenation

前端 未结 7 669
天命终不由人
天命终不由人 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:46

    It's not just for "looks", or for powerful lexical type conversions; it's also a must for internationalisation.

    You can swap out the format string depending on what language is selected.

    With a long line of string concatenations baked into the source code, this becomes effectively impossible to do properly.

提交回复
热议问题