0

I am looking to create a file printing 0 to 10000 with padded zeros

For example: 00001 00002 00003 00004 ... 09999 10000

How could I achieve this? Thank you!

Edit, I see that this was marked as duplicate for the leading zeros, my issue is more the printing all numbers out to file. Thanks!!

triplejjj
  • 19
  • 7

2 Answers2

0

Can you try the following:

>>> ns = '4'
>>> print(ns.zfill(5))
00004

Full example:

for i in range(1, 10001):
    print(str(i).zfill(5))
Jeril
  • 7,858
  • 3
  • 52
  • 69
0

Assuming you are using Python 3.6+:

print(' '.join(f'{i:06d}' for i in range(1, 10_000 + 1)))

For previous versions of Python:

print(' '.join('{:06d}'.format(i) for i in range(1, 10_000 + 1)))
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228