i have a list like this :
a=[1000,200,30]
and i want to get a list like this :
['01000','00200','00030']
so what can i do ,
thanks
>>> a=[1000,200,30]
>>> [str(e).zfill(5) for e in a]
['01000', '00200', '00030']
str.zfill
str.format() is the preferred way to do this if you are using Python >=2.6
>>> a=[1000, 200, 30]
>>> map("{0:05}".format, a)
['01000', '00200', '00030']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With