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!