How do I print curly-brace characters in a string while using .format in Python?

Better Stack Team
Updated on February 2, 2023

To print a curly brace character in a string while using the .format() method in Python, you can use double curly braces {{ and }} to escape the curly braces.

For example:

 
print("{{example}}".format())

This will print the string {example}

You can also use the % operator instead of .format()

 
print("%{example}".format())

This will also print the string {example}

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →