Home > Backend Development > Python Tutorial > How to wrap a string in python and output it

How to wrap a string in python and output it

Release: 2019-11-23 13:43:42
Original
24610 people have browsed it

How to wrap a string in python and output it

Use the escape character \n or use triple quotation marks to achieve string wrap output in python:

Recommended Manual: Python Basics Getting Started Tutorial

Use escape characters\n:

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

Output results:

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

Use triple quotes:

pythonthree Quotation marks allow a string to span multiple lines, and the string can contain newlines, tabs, and other special characters.

>>> hi = '''hi there'''
>>> hi   # repr()
'hi\nthere'
>>> print hi  # str()
hi 
there
Copy after login
Recommended related articles:
1.How to wrap python using cmd
2.How to wrap lines when writing python
Related video recommendations:
1.Little Turtle’s zero-based entry learning Python video tutorial

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

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

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template