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
  • 460
  • 1
  • 3
  • 23

3 Answers3

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

Output

{NOTVAR} name = John
mhhabib
  • 2,975
  • 1
  • 15
  • 29
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
  • 161
  • 1
  • 9