Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
3 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 (46k 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 (106k 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:-

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...