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

Dave S pythontut at pusspaws.net
Wed Apr 28 06:44:43 EDT 2004


Kalle Svensson wrote:

>[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
>  
>
Cheers :-)

Dave



More information about the Tutor mailing list