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

尚
Original
2019-07-01 17:02:1924623browse

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?")

Output results:

I'm Bob.
What's your name?

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
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!

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