+3 votes
2 views
in Python by (3.4k points)
edited by

y = " \{ Hi\} {0} "
print y.format(43)

it's showing an error:

Key Error: Hi\\  

I want to print the output from the above syntax:

 {Hi} 43

2 Answers

0 votes
by (34.9k points)
edited by

It's pretty simple, Just double the {{ and }}

>>> y = " {{ Hi }} {0} "
>>> print y.format(43)
' { Hi } 43 '

Or you can also try this as described by Python documentation.

Cheers...!! 

0 votes
by (73.3k points)

You escape it by doubling the braces.

x = "{{ Hello }} {0}"

print x.format(42)

You can use the following video tutorials to clear all your doubts:-

...