<s>[INST] Nicest way to pad zeroes to string What is the nicest/shortest way to pad a string with zeroes to the left, so the string length has a specific length?
 [/INST] Strings:
>>> n = '4'
>>> print n.zfill(3)
004

And for numbers:
>>> n = 4
>>> print '%03d' % n
004
>>> print format(4, '03') # python >= 2.6
004
>>> print '{0:03d}'.format(4)  # python >= 2.6
004
>>> print '{foo:03d}'.format(foo=4)  # python >= 2.6
004
>>> print('{:03d}'.format(4))  # python >= 2.7 + python3
004
>>> print('{0:03d}'.format(4))  # python 3
004

String formatting documentation.
 </s>