string.format(),其中{}包含在字符串中

Jon*_*han 4 python string

考虑一下您有一个类似于以下内容的字符串,'This string is {{}}'并且希望将其转换为以下内容'This string is {wonderful}'

如果您这样做'This string is {{}}'.format('wonderful'),将无法正常工作。实现此目标的最佳方法是什么?

Mor*_*app 5

您只需要再一对 {}

'This string is {{{}}}'.format('wonderful')
Run Code Online (Sandbox Code Playgroud)