There are two ways to start a new line in Python: use a newline character\nUse a multi-line string (""" or ''')
How to use Python to start a new line
When you need to start a new line in Python code, there are two simple methods:
Method 1: Use newline character
The newline character in Python is \n
, you can break the newline by adding it:
<code class="python">print("段落1\n段落2")</code>
The above code will output:
<code>段落1 段落2</code>
Method 2: Use multi-line strings
Multi-line strings are enclosed in three quotation marks (""" or ''') and are allowed to span multiple lines Write string. Newlines are automatically included in the string:
<code class="python">print("""段落 1 段落 2""")</code>
Output:
<code>段落 1 段落 2</code>
Select method
Both methods can be achieved in Python The purpose of line breaks. Which method you choose depends on the specifics of your code:
In short, starting a new line in Python can be achieved by using the newline character \n
or a multi-line string.
The above is the detailed content of How to start a new line in python. For more information, please follow other related articles on the PHP Chinese website!