escape single bracket in f-string

Justin :

I am trying to print a string in the following format:

"rob: {color: red  , number: 4}"

using an f-string to fill three values:

f"{name}: color: {color}  , number: {number}" #missing brackets

this would print:

"rob: color: red  , number: 4" #missing brackets

but I have no idea how to escape a single bracket the way I need to. I know {{}} lets you escape brackets, but this would print both at the same place in the string. I tried { { } and { } } in their respective spots but this just threw an error.

TheIncorrigible1 :

Goal:

"rob: {color: red  , number: 4}"

Accomplished:

>>> name = 'rob'
>>> color = 'red'
>>> number = 4
>>> print(f"{name}: {{color: {color} , number: {number}}}")
rob: {color: red , number: 4}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=20434&siteId=1