Last Updated on May 15, 2024 by Roshan Parihar
To print text in the next line in a string in Python, use the symbol \n
to add a line break. You can add a string break in text content using this method.
Let’s find out below with the examples.
Print Text in Next Line Using \n in Python
Let us first see the example showing the output without using the newline character. It prints the whole text in the same single line. See the example to print your text in the same line using Python.
Example 1: Without New Line in a String
1 |
print("How are you? I am fine thank you.") |
Output
The above example shows the output containing the text content in the same line. However, in this string text, text content should be in the new line. To get the required text in the next line, you have to use the below-given example
If you want to print the required text content in the new line in Python. You have to use the \n
newline character in the place where you want the line break. Put as many newline characters in the text content as you want. There is no limit to place the number of \n
in the text content.
Example 2: With New Line or Line Breaks in a String
1 |
print("How are you?\nI am fine thank you.") |
Output
I am fine thank you.
The above example uses the single symbol \n
in the text content. The above example uses the print()
to display the text content. It contains a single line break using \n
. However, you can add as many line breaks as per your requirements.
DOWNLOAD Free PYTHON CHEAT SHEET
You may also like to read