Search code examples
pythonstringprintingstring.format

python print double Bracket "{{}}" using .format on it


By using print("""{{1}} {}""".format("x")) I want to print this:

{{1}} x

But I get this:

{1} x

But after using print("""{{{1}}} {}""".format("x"))(three brackets rather than two) I get IndexError: tuple index out of range

So how can I print double brackets using .format on it? Thanks in advance.


Solution

  • Quadruple brackets print("""{{{{1}}}} {}""".format("x")) as double bracket prints one bracket in output so 4 prints two