Python转义“{}”符号

时间:2017-01-02 05:29:01

标签: python string-formatting

我有一个字符串,我在其中使用字符串格式:

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

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

SELECT apples FROM tables WHERE country=home AND {}

1 个答案:

答案 0 :(得分:10)

您可以使用{}

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