Custom Search

Monday, March 16, 2015

How to increment a numeric string '0000000001' in python?

>>>
>>> for x in range(1, 20):
...     "%(#)010d" % {'#': x}

...
'0000000001'
'0000000002'
'0000000003'
'0000000004'
'0000000005'
'0000000006'
'0000000007'
'0000000008'
'0000000009'
'0000000010'
'0000000011'
'0000000012'
'0000000013'
'0000000014'
'0000000015'
'0000000016'
'0000000017'
'0000000018'
'0000000019'
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> for x in range(1, 20):
...     "%(replace)010d" % {'replace': x}

...
'0000000001'
'0000000002'
'0000000003'
'0000000004'
'0000000005'
'0000000006'
'0000000007'
'0000000008'
'0000000009'
'0000000010'
'0000000011'
'0000000012'
'0000000013'
'0000000014'
'0000000015'
'0000000016'
'0000000017'
'0000000018'
'0000000019'
>>>
>>>

http://stackoverflow.com/questions/23270503/how-to-increment-a-numeric-string-0000000001-in-python


No comments:

Post a Comment