[Tutor] makeing '1' into a '01' neatly ?
Dave S
pythontut at pusspaws.net
Wed Apr 28 08:06:54 EDT 2004
Michael Lange wrote:
>On Wed, 28 Apr 2004 12:17:20 +0200
>Kalle Svensson <kalle at lysator.liu.se> 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
>>--
>>
>>
>
>Or just:
>
>
>
>>>>x = '1'
>>>>x.zfill(2)
>>>>
>>>>
>'01'
>
>
>>>>y = '11'
>>>>y.zfill(2)
>>>>
>>>>
>'11'
>
>
>
>Regards
>
>Michael
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
zfill is cool, :-) Its not even in my learning python book !
Dave
More information about the Tutor
mailing list