Python string interpolation using dictionary and strings

后端 未结 8 1236
半阙折子戏
半阙折子戏 2020-12-28 15:49

Given:

dict = {\"path\": \"/var/blah\"}
curr = \"1.1\"
prev = \"1.0\"

What\'s the best/shortest way to interpolate the string to generate t

8条回答
  •  再見小時候
    2020-12-28 16:22

    You can try this:

    data = {"path": "/var/blah",
            "curr": "1.1",
            "prev": "1.0"}
    
    s = "path: %(path)s curr: %(curr)s prev: %(prev)s" % data
    

提交回复
热议问题