打造一个000-999的字典
for i in range(1000): if i<10: i = '00'+str(i) elif 10<=i and i<100: i ='0'+str(i) else: i=str(i) with open('1.txt', 'a') as f: f.write(i+"\n")
本文介绍了一种使用Python编程语言自动生成包含000到999数字序列的字典文件的方法。通过简单的循环结构和字符串处理技巧,可以将这些数字以规定的格式写入文本文件中,方便后续的数据处理或验证使用。
打造一个000-999的字典
for i in range(1000): if i<10: i = '00'+str(i) elif 10<=i and i<100: i ='0'+str(i) else: i=str(i) with open('1.txt', 'a') as f: f.write(i+"\n")
转载于:https://www.cnblogs.com/xiaozi/p/10794903.html
9851
2165

被折叠的 条评论
为什么被折叠?