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