带有 f 字符串的花括号 - ValueError:在字符串格式说明符中不允许符号

pet*_*ush 8 python string python-3.x

以下代码:

a = 0
b = f'{"c": {a}}'
Run Code Online (Sandbox Code Playgroud)

抛出错误:ValueError: Sign not allowed in string format specifier 如何解决?

cs9*_*s95 7

像这样逃离大括号。

>>> f'{{"c": {a}}}'
'{"c": 0}'
Run Code Online (Sandbox Code Playgroud)