How to use newline character in python

silencement
Release: 2019-11-23 11:55:04
Original
87857 people have browsed it

How to use newline character in python

The python program code is as follows:

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

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

I'm Bob. What's your name?
Copy after login

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?
Copy after login

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?")
Copy after login

Output result

I'm Bob. What's your name?
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!