The python implementation outputs the content Branch and the python Branch

Source: Internet
Author: User

The python implementation outputs the content Branch and the python Branch

# Branch output of a line of content in python
 

A = "aA1 one bB2 two cC3 three dD4 four eE5 five fF6 six gG7 seven hH8 eight iI9 nine" branch output: abcdefghiABCDEFGHI123456789 February "print (" Method 1: ====================== ") for r in range ): t = ''for s in range (0 + r, len (a), 4): t = t + a [s] print (t) print (" Method 2: ==================== ") #==_ = will this method look silly? 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: there are N writing methods for the response: ================== ") import stringta = tb = tc = td ='' la = string. ascii_lowercaseua = string. ascii_uppercasenb = string. digitsub = "September 1234" for s in a: if s in la: ta = ta + s if s in ua: tb = tb + s if s in nb: tc = tc + s if s in ub: td = td + sprint (ta) print (tb) print (tc) print (td) print ("method 4: there is a way to write a regular expression = ") import re # This regular expression is not scientific, no good idea for Now 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 1: ==================== abcdefghiABCDEFGHI123456789 1234 five, six, and nine methods 2: ================== abcdefghiABCDEFGHI123456789 method 3: there are N writing methods for returning characters ================== abcdefghiABCDEFGHI123456789 Method 4: there is a way to write a response called regular expression ================== abcdefghiABCDEFGHI123456789 1234 """

Let's give you another way to read the file content and output it by branch.

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 interesting to study it by yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.