Python — ValueError: incomplete format / unsupported format character: Percent Sign Python Format String

I got this error while trying to use % in a string.

"%s %" % "hello" # will return a ValueError. 
# how do we escape the second percetage sign? 

You must escape a percent sign with another percent sign.

	"%s %%" % "hello" 
	# returns hello %
	
	"1%% %s" % "complete" 
	# returns 1% complete

1 Comment

  1. Gnarlodious says:

    Yeah that works, double the Percent Sign and the second one is escaped.

Leave a reply to Gnarlodious Cancel reply