关于字符串格式:Python转义“{}”符号

Python escape “{}” symbol

本问题已经有最佳答案,请猛点这里访问。

我有一个使用字符串格式的字符串:

'SELECT {} FROM {} WHERE country={} AND \{\}'.format("apples","tables","home")

但目前这不起作用;如何转义和以便字符串打印:

1
SELECT apples FROM tables WHERE country=home AND {}


通过使用{{}},可以退出{}序列:

1
2
>>> 'SELECT {} FROM {} WHERE country={} AND {{}}'.format("apples","tables","home")
'SELECT apples FROM tables WHERE country=home AND {}'