python add leading zeros code example
Example 1: python convert number to string with leading zeros
str(1).zfill(2)
# 1 will be '01'
str(23).zfill(4)
# 23 will be '0023'
Example 2: python add zero to string
# add zeros in front of a string
>>> n = '4'
>>> print(n.zfill(3))
004
Example 3: how to append leading zeros in python
str.zfill(width)
Example 4: string format zero padded int python
i = 69
s = f'{i:03}' # for Python >= 3.6, zero padding to have 3 digits
Example 5: how to add extra zeros after decimal in python
>>> format(2.0, '.6f')
'2.000000'