Errors were made when using these two modules, summarized as follows:
1.print
Print will automatically add line breaks when printing, for example:
for in xrange (1,5): ... Print 1234
If you want to block line breaks, add a comma to the argument, and the print is separated by a space, for example:
for in xrange (1,5): ... Print 1 2 3 4
2.strip ()
Split is the whitespace character that is used to remove the first of the string, and the whitespace characters include tab, space, and line breaks, so note that if you do not want to replace tab, specify the removed character to display.
For example:
>>> str1 = ' abc ' >>> str1.strip () ' ABC '
>>> str1 ' abc ' >>> Str1.strip (' a ')
In actual code writing, remember to note the location of the whitespace you need to remove, and if the knowledge removes whitespace characters from one end, use:
Lstrip (): Remove whitespace characters from the beginning of the string
Rstrip (): Remove whitespace characters at the end of a string
When writing a mapreduce program, you often want to slice and remove whitespace characters, especially when you want to pay attention to these details.
Python Print and strip