I have a line where I need curly braces, but also use the f-strings function. Is there any syntax that works for this?
Here are two ways this does not work. I would like to include the literal text " {bar}
" as part of the string.
foo = "test" fstring = f"{foo} {bar}"
NameError: name 'bar' not defined
fstring = f"{foo} \{bar\}"
Syntax Error: part of an f-string expression cannot contain a backslash
Desired Result:
'test {bar}'
Edit: this question seems to have the same answer as How can I print letter shapes in curly braces in a python string, and also use .format on it? but you can only know that if you know that the format function uses the same rules as the f-string. So hopefully this question is relevant for linking f-string finders to this answer.
source share