python – How to escape curly-brackets in f-strings?

python – How to escape curly-brackets in f-strings?

Although there is a custom syntax error from the parser, the same trick works as for calling .format on regular strings.

Use double curlies:

>>> foo = test
>>> f{foo} {{bar}}
test {bar}

Its mentioned in the spec here and the docs here.

python – How to escape curly-brackets in f-strings?

Leave a Reply

Your email address will not be published. Required fields are marked *