[Tutor] What does "TypeError: 'int' object is not iterable"mean?

Alan Gauld alan.gauld at btinternet.com
Fri Oct 22 20:27:57 CEST 2010

"Richard D. Moores" <rdmoores at gmail.com> wrote

>    return ("%%.%sf" % n) % floatt
> which works fine, but a question remains: n is an integer. Why the 
> 's'
> in '%sf'?

Its arbitrary. You could use %d just as easily.
%s will put the numner into the string, so will %d.
%d is probably a bit more picky about what it inserts - so might
actually be a better choice in this case since

float2n(1.234567, 3.5)

Doesn't work as you might hope... but changing it to use %d might - 
on your definition of better! And what you might hope! :-)

OTOH %s handles this better:

float2n(1.234567, '3')


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list