Python Newline: How to Add a New Line and Print Without Newline | Python Tutorial
Printing a new line in Python
Python programmers sometimes need to print some “non-printable” characters.
Include things like a tab or a new line.
To do so, we need to use the backslash character (\) to escape characters. If you do it without the backslash character, it will have a different meaning.
An example
If you want to print a tab, you will use the backslash character just before the letter t, like this: \t.
If you don’t use the backslash character before the letter t, only the letter t will be printed. In this case, no tab will be printed.
print('HellotPython')print('Hello\tPython')//OutputHellotPythonHello PythonPython new line
When you break lines and print content on a new line, the readability of the output is greatly improved.
Whether you write code in Javascript, Python, C++, or Java, the readability of the output is important.
In the case of python, programmers frequently come across the newline character. That is why we need to understand how the newline character works in detail.
Here we will cover the newline character in detail.
New line character in Python
In python, the new line character is represented by “\n”.
It is used to print a new line in the case of the python programming language.
It consists of two characters:
- Backslash
- Letter n.
When you insert the newline character into a string, all characters that appear in the string after the newline characters will be displayed on a new line.
It means that the newline character “\n” tells the compiler that the current line ends here and all characters after me will be displayed on the new line.
Two examples of how you can use the python newline character
1st example

In the example above, you can see that when a newline character is inserted into the string, it breaks across multiple lines.
Most beginners are confused why the ‘\n’ is not printed in the output.
As we discussed earlier, the backslash in the newline character is called an escape sequence.
With the escape sequence character, anything that cannot be printed can be easily printed.
With the help of an escape sequence, the above Python code when executed tells the compiler to print some “unprintable” special characters.
2nd Example
Let’s have some fun with the escape sequences to understand them better.

In string1, the newline character is present after “Hello”.
The newline character (\n) represents the end of the line, and characters after the newline character will be printed on a new line.
In string2, we’ve used a backslash before the newline character, so no newline appears when printing string2.
In string3, we have used two backslashes and it will print one backslash character.
In string4, we have used three backslash characters and it will print two backslashes since the first one will be omitted.
New line character is present in print statements by default
If you take a look at any print statement in python, the newline character is added automatically.
If you write Python code like this:
print("Hello User")This is what it looks like behind the scenes:
"Hello User\n"The newline character is added to everything passed to the print function by default.
If you take a look at the Python documentation.
The default value of the end parameter of the predefined print function is ‘\n’.
That’s why a newline character is added to the end of the string in the print statement.
Here is the definition of the print function:

When you write just a print statement, you won’t be able to see the effect of the newline character.
If you write like this:
print("Hello User")//Output
Hello UserBut when you write multiple print statements at one time. You will be able to see the effect of the new line character.
print("Hello User")
print("How are you")
print("Subscribe to my newsletter")//Output
Hello User
How are you
Subscribe to my newsletterIf there is no newline character after the string “Hello User”, how was the string “How are you” printed on the new line?
This tells us about the presence of the newline character after each string present in the print statement.
How to print without a newline in python
As we have seen before, the new line character (\n) is present by default in the end parameter of the built-in print function.
print("Hello User")
print("How are you")
print("Subscribe to my newsletter")//Output
Hello User
How are you
Subscribe to my newsletterThis is why each string present within the print statement is printed on a new line.
If you want to print without a new line, you must change the value of the end parameter.
You need to change the value of the end parameter and set it to something else.
To do this, instead of using “\n”, you can use a blank “ ”.
Let’s see it through an example:
print("Hello User" , end = " ")
print("How are you", end = " ")
print("Subscribe to my newsletter")//OutputHello User How are you Subscribe to my newsletterIn the example above, we have replaced the end parameter with a space character. Because of this, all three statements will print on the same line.
Multiline strings
With the help of a multi-line string, you can print text on a new line if you want.
The string is spread over multiple lines.
You must use either three double quotes or three single quotes to use this type of string.
When you use 3 double quotes or 3 single quotes, the Python language easily understands what you are trying to do.
This is an example of a multiline string.

In the example above, the string is printed similarly, just as the string is passed to string1.
No newline is present.
If you want, you can easily use multi-line strings.
Summary
The newline character is made up of two characters:
- Backslash
- Letter n
You can use the newline character to print a new line in python.
Change the default value of the end parameter to print without a new line.
Multiline strings are a great alternative if you need them.
Do You Want to Fast Track Your Career as a Programmer
Join a group of people who love programming and technology.
With the help of our community, we will fix major problems in the life of programmers and discuss frontend as well as backend engineering.
We will help you reprogram your understanding of various things in technology.
