Harley provides an awesome method for zero padding a number in a string.
If the number is provided in string format:
n = '4'
print n.zfill(3)
'004'
And for integer format:
n = 4
print '%03d' % n
'004'
Mainly notes to future-Twig (and for anyone else who may find them useful)
If you've found one or more of my blog posts helpful, why not say thanks by buying me a coffee or beer?
Harley provides an awesome method for zero padding a number in a string.
If the number is provided in string format:
n = '4'
print n.zfill(3)
'004'
And for integer format:
n = 4
print '%03d' % n
'004'