Format strings vs concatenation

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

    As of Python 3.6 you can do literal string interpolation by prepending f to the string:

    foo = "foo"
    bar = "bar"
    path = f"{foo}/{bar}"
    

提交回复
热议问题