Home >Backend Development >Python Tutorial >How to wrap python output results in new lines

How to wrap python output results in new lines

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-01 14:19:5021028browse

How to wrap python output results in new lines

The contents output by the print statement are all output horizontally. If you want to restart the output from the second line when the first line of output ends, how to achieve this?

In Python, to implement newline input, you can use the newline character! The newline character is represented by backslash n in Python and is written as \n.

Related recommendations: "Python Video Tutorial"

Let’s take a look at the following example:

If you want to output three hello worlds to the screen continuously, you can Write like this:

How to wrap python output results in new lines

As you can see, the above example implements the function of continuously inputting three hello worlds, but does not implement newline input.

Next Let's add a newline character to the above example and see what it looks like.

How to wrap python output results in new lines

As you can see, the above code achieves the results we expected. It is worth noting that the newline character must be written within the '' quotes of the print statement, and

must not be written as print(\n'hello world').

The above is the detailed content of How to wrap python output results in new lines. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn