Python Print and strip

Source: Internet
Author: User

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

Related Article

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.