How to print a new line in python
In python, if we want to print something to the command prompt there is a built-in function for it which is print(). There are multiple ways you can print a new line.
In this article, we are going to learn how to print a new line in python. Here is some of the way you can print new line:
1. Using the new line character:
Line brank or the new line(\n) is used in different parts of python these are the string, tuple item or list, or dictionary. To use this line brake you can just put them between strings like this:
print("The first new line output:\n this part will print in new line")
// output:
The first new line output:
this part will print in new line
2. Using three double quotes:
You can also print a new line by using three double-quotes. First use three quotes then write the line one after another in a new line.
print("""I
am
learning
Python
""")
// output
I
am
learning
Python
3. Using variables:
You can assign the line break to a variable and use that variable in the print function. Example:
nl = "\n"
print(f"first line{nl}"
f"second line{nl}"
f"third line")
// output
first line
second line
third line
Hope this article helps you to print a new line in python.