x = \" \\{ Hello \\} {0} \"
print(x.format(42))
gives me : Key Error: Hello\\\\
I want to print the output: {Hello} 42>
Although not any better, just for the reference, you can also do this:
>>> x = '{}Hello{} {}'
>>> print x.format('{','}',42)
{Hello} 42
It can be useful for example when someone wants to print {argument}
. It is maybe more readable than '{{{}}}'.format('argument')
Note that you omit argument positions (e.g. {}
instead of {0}
) after Python 2.7