1, the list of a number from small to large sort, and then write to the file, and then read from the file contents of the file:
in [ -]: L = [2, +, +,453, Wu,6,576,5,7,6,8, +,7, the]in [ -]: L.sort () in [ -]: With open ('1.txt','W') asFD: ....: Fd.write (str (l)) ....: in [ -]: With open ('1.txt') asFD: ....: Print Fd.read () ....: [2,5,6,6,7,7,8, +, +, Wu, +, the,453,576]
2, then reverse order, and then append to the next line of the file:
in [ +]: L.reverse () in [ -]: With open ('1.txt','a') asFD: ....: Fd.write (str (l)) ....: in [ +]: With open ('1.txt') asFD: ....: Print Fd.read () ....: [2,5,6,6,7,7,8, +, +, Wu, +, the,453,576][576,453, the, +, Wu, +, +,8,7,7,6,6,5,2]
3. Write the string, list, tuple, dict to the file, respectively:
in [ +]:string='ABC'In [ A]: List = ['a','b','C']in [ at]: tuple = ('a','b','C') in [ -]: Dict = {1:'a',2:'b',3:'C'}in [ -]: With open ('1.txt','W') asFD: ....: Fd.write (string+'\ n') ....: Fd.write (str (list)+'\ n') ....: Fd.write (str (tuple)+'\ n') ....: Fd.write (str (dict)) ....: in [ -]: With open ('1.txt') asFD: ....: Print Fd.read () ....: abc['a','b','C']('a','b','C'){1:'a',2:'b',3:'C'}
Python Third Week job