Home  >  Article  >  Backend Development  >  What is the python newline character?

What is the python newline character?

(*-*)浩
(*-*)浩Original
2019-07-03 14:25:1714155browse

Regarding the issue of line breaks, first ask a question, as follows.

What is the python newline character?

There is python program code: (Recommended learning: Python video tutorial)

print("I'm Bob. What's your name?")

The output of the previous line of code is as follows :

I'm Bob. What's your name?

The above output has no line breaks. I want to wrap the line before What, but the effect is:

I'm Bob.
What's your name?

What should I do?

Hit Enter before What, okay? No, the effect of this carriage return is to wrap the statement, not the output content.

Solution using newline character

The solution to the above problem is to insert a newline character before What. The writing is:

print("I'm Bob.\nWhat's your name?")

Did you notice the \n in front of What? This is a combination of characters, a backslash and the n letter. However, the meaning of this combination is only one character, the newline character.

I emphasize again that the writing method is a combination of two characters, but the meaning is only one character.

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What is the python newline character?. 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