We hope you have learned how to write simple, single-line Python programs that print text. However, real programs contain many lines: from tens or hundreds of lines for small scripts to thousands and even more for large projects. So, in this lesson, you will write programs that print multiple lines.
Ways of printing multiple lines
Let's consider an example. The following code prints exactly three strings, each on a new line:
print("I")
print("know")
print("Python")
The output is:
I
know
Python
You can run this example using this website or locally if you have installed Python on your computer.
There are ways to print the above text using one function call. We will consider them in the following topics.
The print function also allows you to print an empty line with no string specified:
print("I")
print()
print("know")
print("")
print("Python")
Here's the output:
I
know
Python
Note that print() and print("") give the same result!
However, skipping a line in your code will have no effect.
print("And")
print("you?")
The output of the above code is:
And
you?Conclusion
In this short lesson, we learned how to deal with multi-line texts with the help of print(). Now it's time to solve some problems.