I want to iterate serial numbers from 000 to 999 in Python and save them to a txt file
import os os.system ('clear') lis9 = 01000 while lis9 < 01099 : lis9 = lis9+1 print (lis9)
How do I start from a specific number and end at a specific number? The numbers start from zero
Each number begins on a new line
For example
01000 01001 . 01010 . . 01099
Advertisement
Answer
Use f
string
with open('out.txt','w') as f: for n in range(0,1000): f.write(f'{n:03}n')
output (‘out.txt’)
000 001 002 003 ... 996 997 998 999