There are two common ways to output multi-line text in Python: use the newline character \n to break the text into lines. Use three quotes to create a multi-line string and new lines will be added automatically.
How to use print to output multiple lines in Python
In Python, there are many ways to output multiple lines. OK. Here are the two most common methods:
1. Use newline character
Use newline character\n
to split the text into new lines . For example:
print("行 1\n行 2\n行 3")
Output:
行 1 行 2 行 3
2. Using a multi-line string
Use three single quotes or three double quotes to create multiple line string. A new line is automatically added to the end of each line in the string. For example:
print(""" 行 1 行 2 行 3 """)
The output is the same as using newlines.
Other Notes:
end
parameter to specify a newline character. For example,end=" "
will add a space to the end of each line instead of a newline character.The above is the detailed content of How to use print to output multiple lines in python. For more information, please follow other related articles on the PHP Chinese website!