0

I know how to use string format in python

"name = {fname}".format(fname = "John")

The output is name = John

But how can I use if I need to input {} inside the string that not belong to variable , for example

"{NOTVAR} name = {fname}".format(fname = "John")

I want to output will be {NOTVAR} name = John

MicrosoctCprog
  • 370
  • 2
  • 15

3 Answers3

1
print("{{NOTVAR}} name = {fname}".format(fname="John"))

Output

{NOTVAR} name = John
mhhabib
  • 2,733
  • 1
  • 11
  • 22
1

Try


"{{NOTVAR}} name = {fname}".format(fname = "John")

Peeraponw
  • 101
  • 4
1

Probably the simplest way is to seperate it with a +. Something like this:

print("{NOTVAR }" + "name = {fname}".format(fname = "John"))

{NOTVAR} name = John

Simplicitus
  • 162
  • 1
  • 9