Home >Backend Development >Python Tutorial >How to use newline character in python

How to use newline character in python

silencement
silencementOriginal
2019-06-25 15:53:0488010browse

How to use newline character in python

The python program code is as follows:

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 does not have newlines. I want to wrap the line before What, but the effect is:

I'm Bob. 
What's your name?

How to solve it?

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

Recommended manual:Basic introductory tutorial on Python

Solution to using newlines

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

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

Output result

I'm Bob.
What's your name?
Recommended related articles:
1.python removes newlines in strings
2.Introduction to newline characters and tab characters in Python strings
Related video recommendations:
1.Little Turtle’s zero-based introduction to learning Python video Tutorial

The above is the detailed content of How to use newline character in python. 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