left padding zeroes on a string...

Peter Hansen peter at engcorp.com
Fri Mar 25 17:34:12 EST 2005


cjl wrote:
> Hey all:
> 
> I want to convert strings (ex. '3', '32') to strings with left padded
> zeroes (ex. '003', '032'), so I tried this:
> 
> string1 = '32'
> string2 = "%03s" % (string1)

string1.zfill(3)

-Peter



More information about the Python-list mailing list