-2

I would like the output to be this

I'm using '%s' to print this out: hello!

My code:

print "I'm using %s to print this out: %s" % "hello!"

This returns an error.

Gautham SK
  • 69
  • 2
  • 10

1 Answers1

6

Put a second % before the literal one:

print "I'm using %%s to print this out: %s" % "hello!"

This isn't a Python-specific solution: C's printf, and other analogues (such as the shell printf) work the same way.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441