[python打印双括号“ {{}}”,在其上使用.format

问题描述 投票:0回答:1

通过使用print("""{{1}} {}""".format("x")),我想打印此:

{{{1}} x

但是我明白了:

{1} x

但是在使用print("""{{{1}}} {}""".format("x"))(三个而不是两个)之后,我得到了IndexError: tuple index out of range

所以如何在.format上打印双括号?预先感谢。

python string printing string.format
1个回答
1
投票

作为双括号的四括号print("""{{{{1}}}} {}""".format("x"))在输出中打印一个括号,因此四打印两个]

© www.soinside.com 2019 - 2024. All rights reserved.