Andrew Parker Andrew Parker - 3 months ago 16
Python Question

Python treats "is" to pluralize string literal

Python version 3.4.3

Python converting string literal to plural. I cannot figure out how to solve this.

When I enter:

>>> x = ("The number % is incorrect" % 8)
>>> x
'The number 8s incorrect'


When I try to escape "is" I get an error.

>>> x = ("The number % \is incorrect" % 8)
ValueError: unsupported format character '\' (0x5c) at index 13

Answer

Try 'the number %d is incorrect' % 8

The problem is that python is reading your % (with the space, thanks, Ashwini) , and thinking that is your format character.

Comments