1. 把一个数字的list从小到大排序,然后写入文件,然后从文件中读取出来文件内容,然后反序,在追加到文件的下一行中
2. 分别把 string, list, tuple, dict写入到文件中
import codecs l=[2,4,5,222,3,10,6,8,11,22,33,55,44] a=sorted(l) with open('aa.txt','w') as f1: f1.write(str(a)) l.sort() l.reverse() with open('aa.txt','a') as f2: f2.write((str(l))) string = 'abc' list = ['a', 'b', 'c'] tuple = ('a', 'b', 'c') dict = {1:'a', 2:'b', 3:'c'} with open('b.txt','a') as f3: print(f3.write(string+' ')) print(f3.write(str(list) + ' ')) print(f3.write(str(tuple) + ' ')) print(f3.write(str(dict) + ' ')) with open('b.txt','ab+') as f4: print(f4.read())