formatting a number as percentage
dickinsm at gmail.com
Sun Feb 21 19:15:18 CET 2010
On Feb 21, 5:53 pm, vsoler <vicente.so... at gmail.com> wrote:
> I'm trying to print .7 as 70%
> I've tried:
> print format(.7,'%%')
> but neither works. I don't know what the syntax is...
Assuming that you're using Python 2.6 (or Python 3.x):
>>> format(.7, '%')
>>> format(.7, '.2%')
Or see TomF's response for how to use this with the str.format method.
More information about the Python-list