Python ProgrammingPython Programming

Python pad string with zeros

number = 4

print(f'{number:05d}')  # (since Python 3.6), or
print('{:05d}'.format(number))  # or

print('{0:05d}'.format(number))
print('{n:05d}'.format(n=number))  # or (explicit `n` keyword arg. selection)
print(format(number, '05d'))
Output
00004
00004
00004
00004
00004
00004