You need to double the {{ and }}:

>>> x = " {{ Hello }} {0} "
>>> print(x.format(42))
' { Hello } 42 '

Here's the relevant part of the Python documentation for format string syntax:

Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

Answer from Greg Hewgill on Stack Overflow
🌐
LabEx
labex.io › questions › how-to-escape-curly-braces-in-fstrings-7847
How to Escape Curly Braces in Python F Strings | LabEx
July 25, 2024 - To escape curly braces in an f-string, you need to double the curly braces. This tells Python to treat the curly braces as literal characters rather than as part of the expression.
Discussions

escape curly brackets before f-string formatting in FewShotPromptTemplate
In the current version(0.0.147), we should escape curly brackets before f-string formatting (FewShotPromptTemplate) by ourselves. More on github.com
🌐 github.com
4
April 23, 2023
Curly braces in string without f
>>> foo = "foo {bar}" >>> print(foo.format(bar="foo")) foo foo it's for the slightly older but still used way of formatting strings More on reddit.com
🌐 r/learnpython
22
4
August 7, 2025
How do I use text.format() when the text has curly braces from HTML CSS?
I have e.g. this code: helpAbout = """ Author: {} """ print(helpAbout.format(__author__)) which fails, because Python tries to insert __author__ where the curly braces from the CSS style command are. I help myself by using the outdated ‘%’ formatting option. helpAbout = """ Author: %s """ ... More on discuss.python.org
🌐 discuss.python.org
3
0
September 2, 2022
python's print(f"{format}") issues with nested curly braces. My need is for automating some latex formulas which needs a ton of nested curly braces like: $$\binom{10}{0}\cdot 0.25^{0}\cdot0.75^{(10-0)}$$
Consider importing a library that does a lot of this for you. Having the program produce strings is the worst of both worlds - the complexity of LaTeX, plus the annoyances of string formatting. More on reddit.com
🌐 r/learnpython
5
3
May 16, 2022
🌐
AskPython
askpython.com › python › string › escape-curly-braces-string
How To Escape '{}' Curly braces In A String? - AskPython
May 31, 2023 - The curly braces are used to replace the value using the format method and f-string methods. This is a very useful method for the customization of strings. Let’s see how these curly braces will escape from the strings.
🌐
GitHub
github.com › langchain-ai › langchain › issues › 3382
escape curly brackets before f-string formatting in FewShotPromptTemplate · Issue #3382 · langchain-ai/langchain
April 23, 2023 - --------------------------------------------------------------------------- IndexError Traceback (most recent call last) [<ipython-input-9-95e0dc90fc4d>](https://localhost:8080/#) in <cell line: 16>() 14 ) 15 ---> 16 fewshot_prompt.format(**example) 6 frames [/usr/lib/python3.9/string.py](https://localhost:8080/#) in get_value(self, key, args, kwargs) 223 def get_value(self, key, args, kwargs): 224 if isinstance(key, int): --> 225 return args[key] 226 else: 227 return kwargs[key] IndexError: tuple index out of range ... # What should we do: escape brackets in examples def escape_examples(examp
Author   langchain-ai
🌐
Reddit
reddit.com › r/learnpython › curly braces in string without f
r/learnpython on Reddit: Curly braces in string without f
August 7, 2025 -

Hey everyone, I have a quick question regarding the use of curly brackets in strings, but I couldn’t find an answer online.

So I know that using f-strings, curly braces inside the string will get replaced with the variable/expression inside. If I want to include the literal { } characters in the string, however, I just have to double them {{}}.

But what happens if I’m not using an f-string and I include the curly braces in the string? I tried this and it prints the literal symbols, but in VSCode, the expression in the code including the braces turns blue. What does this mean?

Edit: thanks everyone for your responses!

🌐
Python.org
discuss.python.org › python help
How do I use text.format() when the text has curly braces from HTML CSS? - Python Help - Discussions on Python.org
September 2, 2022 - I have e.g. this code: helpAbout = """ Author: {} """ print(helpAbout.format(__author__)) which fails, because Python tries to insert __author__ where the curly braces from the CSS style command are. I help myself by using the outdated ‘%’ formatting option. helpAbout = """ Author: %s """ prin...
Find elsewhere
🌐
Django CAS
djangocas.dev › blog › python › python-literal-curly-braces-in-f-string
Python: How to print literal curly brace { or } in f-string and format string
July 10, 2024 - ... Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.
🌐
Better Stack
betterstack.com › community › questions › how-to-print-curly-brace-in-python-string
How do I print curly-brace characters in a string while using .format in Python? | Better Stack Community
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: Copied! print("{{example}}".format()) This will print the string {example} ...
🌐
Pythonkitchen
pythonkitchen.com › home › software engineering › how to escape curly braces in python string formatting
How to Escape Curly Braces in Python String Formatting | Python Kitchen
May 9, 2018 - In this guide, we’ll look at the correct way to escape braces in both .format() and f-strings. If you are using the .format() method, the rule is simple: Double the braces. To print {, use {{. To print }, use }}. content = "Hello World" # ...
🌐
Python
peps.python.org › pep-0498
PEP 498 – Literal String Interpolation | peps.python.org
A single closing curly brace '}' ... closing curly braces must be doubled '}}' in order to represent a single closing brace. The parts of the f-string outside of braces are literal strings.
🌐
Reddit
reddit.com › r/learnpython › python's print(f"{format}") issues with nested curly braces. my need is for automating some latex formulas which needs a ton of nested curly braces like: $$\binom{10}{0}\cdot 0.25^{0}\cdot0.75^{(10-0)}$$
python's print(f"{format}") issues with nested curly braces. ...
May 16, 2022 -

Solved:

The issue below is solved by adding 3 curked brackets like {{{x}}} or even {{({x}-{y})}}

(where x-y is meant to show as an latex equation)



I want to print latex friendly code from python which means printing curly braces, but I'm running into a few issues regarding the print formating of python [ the f"{string}" thing].

Anyone knows how to correctly do it? Or there is no support yet for nested curly braces on python?

The link for my code can be seen here: https://trinket.io/python3/08dd26b052

I'll also paste the relevant part of the code here so you can glance at it real quicky:

The "hack" I had to do was using "<" and ">" since they don't mess with the print statement.

Then I have to open up any text editor that has an "replace all" button and change all every angled brace for their respective curled brace (which is tedious, but less tedious than typing 5 similar latex equations)

import matplotlib.pyplot as plt
from math import comb

height = []
n=10
for k in range (6):
    print(f"$$\\binom<{n}><{k}>\\cdot 0.25^<{k}>\cdot0.75^<({n}-{k})>$$")
🌐
Reddit
reddit.com › r/learnpython › f-strings with double curly braces
r/learnpython on Reddit: f-strings with double curly braces
May 22, 2020 -

Hey guys, I am currently trying to POST data to an airtable database, but I cant get my variables to work, either f-string or .format. I tried double curlies at the beginning and end, and like this case double curlies for the variables... What am I doing wrong? 😅

Thanks a lot!

data = '{\n  "fields": {\n    "Entry number": "1",\n    "email adress": "{{}}",\n    "password": "{{}}"\n  },\n  "typecast": true\n}'.format(user_name, user_password)
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
You can add parameters inside the curly brackets to specify how to convert the value: Format the price to be displayed as a number with two decimals: txt = "The price is {:.2f} dollars" Try it Yourself » · Check out all formatting types in our String format() Reference.
🌐
GitHub
github.com › langchain-ai › langchain › issues › 1660
How to escape curly-braces "{}" in a customized prompt? · Issue #1660 · langchain-ai/langchain
March 14, 2023 - Hi. I am trying to generate a customized prompt where I need to escape the curly-braces. Whenever I use curly braces in my prompt, it is being taken as place holders. So, can you please suggest how to escape the curly braces in the prompts?
Author   langchain-ai
🌐
Java2Blog
java2blog.com › home › python › python string › escape curly brace in f-string in python
Escape Curly Brace in f-String in Python - Java2Blog
May 18, 2022 - Now, what if we need to escape curly braces in f-strings in Python. For this, there is a simple fix of using two curly braces instead of one.
🌐
Python Guides
pythonguides.com › escape-curly-braces-in-python-format-strings
How To Escape Curly Braces In Python Format Strings?
January 28, 2025 - In this tutorial, I have explained how to escape curly braces in Python format string. I discussed several ways to format strings, including the str.format() method, and the more recent f-strings and percent formatting.
🌐
Codemia
codemia.io › home › knowledge hub › how do i escape curly-brace characters characters in a string while using .format?
How do I escape curly-brace characters characters in a string while using .format? | Codemia
September 23, 2025 - Even though the original question is about .format, the same escaping rule applies to f-strings. ... The result contains literal braces around the interpolated value. This consistency helps because you do not need two different mental models for Python string interpolation.
🌐
Medium
medium.com › @venu_madhav › master-the-python-f-string-26a426459bdb
Python variables | python print funtion | python loops | python control statements | python class | ML with python | lists | python f-strings | Medium
March 25, 2024 - Using f-strings is super easy! Just prefix your string with ‘f’ or ‘F’, and then place your variables or expressions inside curly braces {}. Python will automatically replace them with their values.
🌐
Python Tutorial
pythontutorial.net › home › python basics › python f-strings
Python F-strings: a Practical Guide to F-strings in Python
March 30, 2025 - The f-strings provide a way to embed variables and expressions inside a string literal using a clearer syntax than the format() method. ... How it works. First, define a variable with the value 'John'. Then, place the name variable inside the curly braces {} in the literal string.