[Tutor] makeing '1' into a '01' neatly ?

Kalle Svensson kalle at lysator.liu.se
Wed Apr 28 06:17:20 EDT 2004


[Dave S]
> I need strings of the form 01, 02, 03 ... ,10,11,12 ... for
> archiving files.
> 
> Is there an neat way to format a '1' into a '01' ?

>>> for x in '1', '3', '30':
...     print '%02d' % int(x)
... 
01
03
30

Peace,
  Kalle
-- 
Kalle Svensson, http://www.juckapan.org/~kalle/
Student, root and saint in the Church of Emacs.



More information about the Tutor mailing list