python – How can I generate a list of all combinations of digits in a four digit number?

Question:

How can I generate a list of all combinations of digits in a four digit number?

The first digit can contain 0. There are 4 digits, each can contain a number from 0 to 9. As I understand it, this is 10^4 .

How can this be implemented?

Answer:

If you're not smart, then you just need to print the string representation of numbers up to 9999 with leading zeros:

for i in range(10000):
    print('{:04d}'.format(i))
Scroll to Top
AllEscort