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
🌐
Manifoldapp
cuny.manifoldapp.org › read › how-to-code-in-python-3 › section › 07f9968a-8f75-4d3c-8573-2e9282745e9e
How To Use String Formatters | How To Code in Python 3 | Manifold @CUNY
This tutorial will guide you through ... and user friendly. Formatters work by putting in one or more replacement fields or placeholders — defined by a pair of curly braces {} — into a string and calling the str.format() method....
Discussions

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
0
0
September 2, 2022
Curly bracket in this code (beginner)
Inside an “f-string” those are references to variables. So it’ll swap in first and last into the full_name string on execution. More on reddit.com
🌐 r/learnpython
9
13
October 21, 2023
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
f-strings with double curly braces
You are wildly over-complicating this. There is no need for a format string here, just do: data = {"fields": {"Entry number": "1", "email address": user_name, "password": user_password, "typecast": True}} More on reddit.com
🌐 r/learnpython
19
1
May 22, 2020
🌐
LabEx
labex.io › tutorials › python-how-to-properly-format-python-strings-with-curly-braces-415681
How to Properly Format Python Strings with Curly Braces | LabEx
By understanding the basics of ... format strings more efficiently. This technique is known as "f-strings" (formatted string literals) or "string interpolation"....
🌐
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...
🌐
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} ...
🌐
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 - f_string ::= (literal_char | "{{" | "}}" | replacement_field)* replacement_field ::= "{" f_expression ["="] ["!" conversion] [":" format_spec] "}" f_expression ::= (conditional_expression | "*" or_expr) ("," conditional_expression | "," "*" or_expr)* [","] | yield_expression conversion ::= "s" | "r" | "a" format_spec ::= (literal_char | NULL | replacement_field)* literal_char ::= <any code point except "{", "}" or NULL> The parts of the string outside curly braces are treated literally, except that any doubled curly braces '{{' or '}}' are replaced with the corresponding single curly brace. A single opening curly bracket '{' marks a replacement field, which starts with a Python expression.
🌐
W3docs
w3docs.com › python
How do I print curly-brace characters in a string while using .format?
string = "{{This is a string with curly braces}}" formatted_string = "The value is: {}".format(string) print(formatted_string)
Find elsewhere
🌐
Python
docs.python.org › 3.3 › library › string.html
6.1. string — Common string operations — Python 3.3.7 documentation
March 9, 2022 - 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.
🌐
PythonHow
pythonhow.com › how › print-literal-curly-brace-characters-in-a-string-and-also-use-dotformat-on-it
Here is how to print literal curly-brace characters in a string and also use .format on it in Python
To print literal curly braces in a string and also use the .format() method on the string, you can use double curly braces to escape the braces. You can then use the .format() method on the string as you normally would, like this: string = "{{}}" formatted_string = string.format("Hello, world!") ...
🌐
SheCanCode
shecancode.io › home › news & articles › string formatting in python
String Formatting in Python - SheCanCode
December 11, 2023 - We can mention the format specifier inside the curly brackets. It allows us to control the formatting of the values. Like if we mention {:,.2f} →It indicates two decimal places.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to format a string that contains curly braces in python?
How To Format A String That Contains Curly Braces In Python? - Be on the Right Side of Change
September 27, 2020 - We already discussed that {} inside a format string are special characters, therefore if we want to include braces as a part of our literal text, we need to tell the .format string parser that the given curly braces must be escaped and considered as a part of the given text literal.
🌐
Python Tutorial
pythontutorial.net › home › python basics › python f-strings
Python F-strings: a Practical Guide to F-strings in Python
March 30, 2025 - Python f-strings provide an elegant way to format text strings. Python replaces the result of an expression embedded inside the curly braces {} in an f-string at runtime.
🌐
sqlpey
sqlpey.com › python › python-literal-curly-braces-formatting
Python String Formatting: How to Include Literal Curly Braces
October 29, 2025 - Exploring various techniques in Python to output literal curly braces {} within formatted strings using .format() and f-strings.
🌐
Wyzant
wyzant.com › resources › ask an expert
How can I print literal curly-brace characters in python string and also use .format on it? | Wyzant Ask An Expert
March 26, 2019 - x = " \\{ Hello \\} {0} " print x.format(42) gives me : `Key Error: Hello\\\\`I want to print the output: `{Hello} 42` ... Joshua C. answered • 04/07/19 ... Get a free answer to a quick problem. Most questions answered within 4 hours.
🌐
Linux Hint
linuxhint.com › python-string-formatting-tutorial
Python String Formatting Tutorial
September 10, 2023 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
AskPython
askpython.com › home › how to escape ‘{}’ curly braces in a string?
How To Escape '{}' Curly braces In A String? - AskPython
May 31, 2023 - Format method is a built-in method in Python that helps to replace the values from the string. Usually, this format method is used for the customization of the strings. For example, using this format method, we can add different string values, float numbers, characters, or integers to the string after providing curly braces. Here, the curly braces are used instead of the values in the string. During execution, these values will be replaced with the help of the format method.
🌐
Data Science for Everyone
matthew-brett.github.io › teaching › string_formatting.html
Inserting values into strings — Tutorials on imaging, computing and mathematics
This method works for all current releases of Python. Here we insert a string into another string: >>> shepherd = "Mary" >>> string_in_string = "Shepherd {} is on duty.".format(shepherd) >>> print(string_in_string) Shepherd Mary is on duty. The curly braces show where the inserted value should go.
🌐
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 - It is considered faster than the other methods of format() function and the % operator. We will discuss how to escape curly braces in f-strings in Python in this tutorial. First, let us understand what it means to escape a character. A character in a string can have some specific function and escaping here indicates a way to reduce the ambiguity and confusion so that the character is treated normally. Now, we will discuss the use of curly braces in f-strings. With ...
🌐
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)}$$
r/learnpython on Reddit: 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)}$$
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})>$$")