python add zero to string
# add zeros in front of a string
>>> n = '4'
>>> print(n.zfill(3))
004
python add zero to string
# add zeros in front of a string
>>> n = '4'
>>> print(n.zfill(3))
004
python3 format leading 0
print(f"{1:02d}")
python add zero to string
# add zeros to numbers
>>> n = 4
>>> print(f'{n:03}') # Preferred method, python >= 3.6
004
>>> print('%03d' % n)
004
>>> print(format(n, '03')) # python >= 2.6
004
>>> print('{0:03d}'.format(n)) # python >= 2.6 + python 3
004
>>> print('{foo:03d}'.format(foo=n)) # python >= 2.6 + python 3
004
>>> print('{:03d}'.format(n)) # python >= 2.7 + python3
004
python3 format leading 0
print("{:02d}".format(1))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us