[PYTHON] Escape curly braces in the format string

When using a format string in Python, use curly braces to specify placeholders. If you want to use the curly braces themselves as a string, you need to overlay the curly braces as follows.

Escape of curly braces


>>> 'test {{{0}}}'.format('hoge')
'test {hoge}'

Note that you cannot escape with a backslash.

(ref) http://docs.python.org/2.7/library/string.html#formatstrings

Recommended Posts

Escape curly braces in the format string
[Python 2/3] Parse the format string
Get the query string (query string) in Django
String format
python: Use the variables defined in the string format as they are
What's in the parameter? Edit String & Expression
Python string format
Change the device (drive) label in vfat format.
Python string format
format in python
json.dumping None in python returns the string null
String to Unicode Escape Sequence Format for Python
Correct the week set by index in datetime format
Get the result in dict format with Python psycopg2
Read the linked list in csv format with graph-tool
Shift the alphabet string by N characters in Python
Extract the element by deleting the tag contained in the string
String manipulation in python
Image format in Python
[Python3] Format the character string using the variable name as the key.
Set the DateTime type output format in your Django template
I was in trouble because the character string in the PDF was strange
Find out the apparent width of a string in python
Get the MIME type in Python and determine the file format
Sort the string array in order of length & Japanese syllabary
Find out how many each character is in the string.
In Django, how to abbreviate the long displayed string as ....
Summary of character string format in Python3 Whether to live with the old model or the new model