如何在Python 3'''字符串中转义char?

DNB*_*ims 6 string escaping string-formatting python-3.x

这是字符串:

'''This is a test { <-- escape these ---> } '''
Run Code Online (Sandbox Code Playgroud)

我想逃避

{

}

在格式化方法中,我该怎么办?谢谢.

Mar*_*ers 8

格式字符串语法:

如果您需要在文字文本中包含大括号字符,可以通过加倍{{和}}来对其进行转义.

试试这个:

'''This is a test {{ <-- escape these ---> }} and the value is {0}'''.format(42)
Run Code Online (Sandbox Code Playgroud)