#python版一行内容分行输出
A= "AA1 bB2 two cC3 three dD4 four eE5 five fF6 six gG7 seven hH8 eight iI9 Nine" "" Branch output: abcdefghiABCDEFGHI123456789 123456789 "" "Print (" Method one: =========== = = ") for R in range (0,4): t= ' for S in range (0+r,len (a), 4): T=t+a[s] Print (t) print (" Method two: =============== ") #=_= This method will not look Are you stupid? L=list (a) ta=tb=tc=td= "for R in range (0,9): for S in range (0,4): If S==0:ta=ta+l.pop (0) if S==1:tb=tb+l.pop ( 0) if S==2:tc=tc+l.pop (0) if S==3:td=td+l.pop (0) print (TA) print (TB) print (TC) print (TD) Print ("Method 3: Word back has n notation ========== ===== ") Import stringta=tb=tc=td=" la=string.ascii_lowercaseua=string.ascii_uppercasenb=string.digitsub= " 123456789 "for S in a:if s in La:ta=ta+s if s in Ua:tb=tb+s if S-nb:tc=tc+s if s in Ub:td=td+sprint (TA) print (TB Print (TC) print (TD) Print ("Method 4: There is a word called regular notation ===============") import re# this regular writing feeling unscientific, there is no good idea reg=["[A-Z]", "[A-Z]", "\ D "," [^\da-za-z] "]for s in Reg:rega=re.compile (s) s=re.findall (rega,a) print (" ". Join (s))" "Output: Method one: =============== abcdefghiABCDEFGHI123456789 123456789 Method Two: ===============abcdefghiabcdefGHI123456789 123456789 Method 3: The word back has n notation ===============abcdefghiabcdefghi123456789 123456789 Method 4: The word back has a form called regular =========== ====abcdefghiabcdefghi123456789 123456789 "" "
And give you a way to read the contents of the file and branch out
F=open ("Shuju.txt", "R") Content=f.read () print contentfor i in content: print if.close () f=open (' Shuju.txt ', ' W ') F.write (content) F.close ()
Well, it's fun for the little friends to do their own research.