Home >Backend Development >Python Tutorial >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!