A
A
ADRian2016-04-09 04:26:26
Python
ADRian, 2016-04-09 04:26:26

How to escape characters '{' and '}' in str.format()?

For example, how to get a string like: "a_{bc}"?
"{}_{{} {}}".format('a', 'b', 'c') or "{}_\{{} {}\}".format('a', 'b' , 'c') doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lertmind, 2016-04-09
@ADR

Add another parenthesis: "{{, }}".format() # Outputs: {, }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question