在最近的Python版本中 f-strings PEP498 ).
对于f字符串,应该使用double {{ 或 }}
{{
}}
n = 42 print(f" {{Hello}} {n} ")
{Hello} 42
如果需要解析方括号中的表达式而不是使用文本,则需要三组方括号:
hello = "HELLO" print(f"{{{hello.lower()}}}")
生产
{hello}