Print Braces {}

Asked 2 years ago, Updated 2 years ago, 68 views

I want to print {} how do I write it? There's an error in the way I wrote it I want to print it out like {Hello} 42.

Key Error: Hello\\

x = " \{ Hello \} {0} "
print x.format(42)

string python format

2022-09-21 15:50

1 Answers

{{, }Write } The contents in {} are considered literal text. If you want to print {, you must write it twice, such as {.

x = " {{ Hello }} {0} "
print x.format(42)

Documents related to this are located in Format String Syntax.


2022-09-21 15:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.