Python3 print output with blank line problem and workaround

Source: Internet
Author: User

Python3 read 1.txt and print output to 2.txt

The printout has a blank line, because the text has been brought with a ' \ n ', and the print default is ' \ n ', so the two lines are changed.

Workaround

1) Strip (): Used to remove the character specified by the tail of the string (the default is a space)

Add a sentence Line.strip () to remove the text with the ' \ n '

2) Add end= '

Two important parameters in print (), Sep and end: Custom Spacers (default spaces) and terminator (default carriage return)

Adding end= ' means passing an empty string for the end parameter of print so that the print function does not add a line break at the end of the string, but instead adds an empty string.

Python3 print output with blank line problem and workaround

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.