Replacing specific words in a string (Python)

后端 未结 3 786
你的背包
你的背包 2020-11-29 10:48

I would like to replace words in a string sentence such as:

What $noun$ is $verb$?

What\'s the regular expression to replace the characters

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 11:23

    Given that you are free to modify $noun$ etc. to your liking, best practise to do this nowadays is probably to using the format function on a string:

    "What {noun} is {verb}?".format(noun="XXX", verb="YYY")
    

提交回复
热议问题