-4

I am trying to repeatedly ascend integers in the format of 000, 001, I have attempted to do the following

>>> for x in range(000, 999):
        ...

BUT, it returns..

1
2
3
4...
  • What return type do you need at the end of all of these operations because leading zeros are not allowed for decimal numbers – Kaleba KB Keitshokile Apr 18 '22 at 01:30
  • 3
    Leading zeros is not a thing in `python` `integer` type. But `string` formatting is what you're looking for. – MSH Apr 18 '22 at 01:31
  • 1
    Does this answer your question? [How to pad zeroes to a string?](https://stackoverflow.com/questions/339007/how-to-pad-zeroes-to-a-string) – solarissmoke Apr 18 '22 at 05:32

1 Answers1

0

You can do it like this.

for i in range(0, 1000):
    print(f"{i:03}")

Addendum: If you simply want to print it, you need to convert it to string. You cannot have 001 in an integer format.

Edit: change the range to end at 1000, if you want to print 999.

Seven
  • 330
  • 2
  • 15