python - 带有 f 字符串的花括号 - ValueError : Sign not allowed in string format specifier

标签 python python-3.x string

<分区>

以下代码:

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

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

最佳答案

像这样转义大括号。

>>> f'{{"c": {a}}}'
'{"c": 0}'

关于python - 带有 f 字符串的花括号 - ValueError : Sign not allowed in string format specifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53916092/

相关文章:

python - Boost.Python 向现有 PyObject 添加绑定(bind)(用于异常处理)

python - 删除时序列化模型对象时的AttributeError

python-3.x - Python 3.6 numpy reshape 可以工作,但值包含 e

python - 如何转换非常大的数据框以获取所有列中的值的计数(不使用 df.stack 或 df.apply)

swift - 将 ASCII 符号插入字符串 (Swift)

c - 段错误 : Trying to write array of strings in shared memory c

python - 如何使用带有 for 或 while 循环的 MySQLdb SELECT

python - 如何在 NumPy 中有效计算列式外向量

python-3.x - PyCharm 为自身使用的类输入提示

java - 如何在 Java 中将数组字符右移?