Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape char in Python 3 ''' string?

Here is the String:

'''This is a test { <-- escape these ---> } '''

I would like to escape the

{

and

}

in format method, how can I do so? Thanks.

like image 863
DNB5brims Avatar asked Nov 30 '11 08:11

DNB5brims


1 Answers

Format String Syntax:

If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

Try this:

'''This is a test {{ <-- escape these ---> }} and the value is {0}'''.format(42)
like image 61
Mark Byers Avatar answered Sep 30 '22 12:09

Mark Byers