带f字符串的大括号-ValueError:字符串格式说明符中不允许使用符号

时间:2018-12-24 17:11:22

标签: python python-3.x string

以下代码:

a = 0
b = f'{"c": {a}}'

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

1 个答案:

答案 0 :(得分:2)

像这样逃避牙套。

>>> f'{{"c": {a}}}'
'{"c": 0}'
相关问题