Python: Write little programs every day

Source: Internet
Author: User

Every day to write a little Python applet, below is a TXT file inside of the count of words, look at the other people's

1File_name="E:\movie.txt"2 #Python Learning Group 1252409633  4 5line_counts=06 7word_counts=08 9character_counts=0Ten  One   A  -With open (file_name,"R") as F: -  the      forLineinchF: -  -words=Line.split () -  +Line_counts+=1 -  +word_counts+=Len (words) A  atcharacter_counts+=Len (line) -  -   -  -   -  in Printline_counts -  to Printword_counts +  - PrintCharacter_counts

I didn't know it could be used for lines in F, which represents the cycle of getting each line.

And Len is adding the last \ n

If you do not add parameters to split (), the default is to consider a space delimiter, such as "FDSF Fdsafds FSDA"

In this case, it will be divided into three, no matter how many of the space, nothing can see the Python document, do some experiments.

Python: Write little programs every day

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.