Python 转义“{}”符号

Python escape "{}" symbol

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

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

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

SELECT apples FROM tables WHERE country=home AND {}

?

您可以使用 {{}}:

转义 {} 序列
>>> 'SELECT {} FROM {} WHERE country={} AND {{}}'.format("apples", "tables","home")
'SELECT apples FROM tables WHERE country=home AND {}'