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
Advertisements

One thought on “Python — ValueError: incomplete format / unsupported format character: Percent Sign Python Format String

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s