How to display a list of numbers with leading zeros in Python

1 Answer

0 votes
lst = [3, 12, 7, 5, 15, 871]

for n in lst:
    print (str(n).rjust(4, '0'))




'''
run:

0003
0012
0007
0005
0015
0871

'''

 



answered Feb 3, 2022 by avibootz
...