小编Vid*_*tam的帖子

如何在 Python 3 中向 f 字符串添加大括号?

我有这个代码

class = "maximum"
s = f"""The code for {class} is {3854-st56}"""
print(s)
Run Code Online (Sandbox Code Playgroud)

我想要这个输出:

>> The code for maximum is {3854-st56}
Run Code Online (Sandbox Code Playgroud)

但 f 字符串无法识别 3854-st56 周围的大括号,而是认为我正在尝试输入实际的 Python 代码。如何使 f 字符串识别大括号是字符串文字。

python python-3.x f-string

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

f-string ×1

python ×1

python-3.x ×1