如何在 f 字符串内使用花括号

13 浏览
0 Comments

如何在 f 字符串内使用花括号

这个问题已经有了答案::

如何在f字符串中转义大括号? [重复]

我尝试在Python中使用f字符串进行以下操作

test=f"""
{
"""
print(test)

它出现了错误

  Input In [39]
    """
       ^
SyntaxError: f-string: expecting '}'

我希望它输出{,就像它原来的样子一样

admin 更改状态以发布 2023年5月21日
0
0 Comments

你可以尝试:

test = f"""{{"""
print(test)

或者

test = f"{'{'}"
print(test)

0